首先,我很抱歉我的英语不好。 :)
我必须找出点击了哪个项目才能将其添加到ArrayList中。如果连续单击项目,我想在ArrayList中连续添加它们。
final ArrayList oldPostion = new ArrayList<Integer>();
ArrayAdapter adapterONE = new ArrayAdapter(this,android.R.layout.simple_list_item_activated_1, list);
ListView one = (ListView) findViewById(R.id.listViewOne);
one.setAdapter(adapterONE);
one.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
oldPostion.add(position);
int something = 0;
if(oldPostion != null && oldPostion.get(position - 1) != null){
if( oldPostion.get(position - 1) == position){
//do something like this
Toast.makeText(getApplicationContext(), "Item First Item" + "Selected Item" + one.getAdapter().getItem(position), Toast.LENGTH_LONG).show();
something = 1 + 1;
}else if(oldPostion.get(position) == position){
//do something like this
Toast.makeText(getApplicationContext(), "Item Second Item" + "Selected Item" + one.getAdapter().getItem(position) , Toast.LENGTH_LONG).show();
something = 1 - 1;
}
//Result
Toast.makeText(getApplicationContext(), Integer.toString(something), Toast.LENGTH_LONG).show();
}
}
}
答案 0 :(得分:0)
要在public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
添加
TextView tv = (TextView) view.findViewById(R.id.the_text_view_id);
String text = tv.getText().toString();