這是我onItemClickListener方法無法更改的TextView,ListView中
//list item listener
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
LinearLayout parent = (LinearLayout) view;
TextView t = (TextView) parent.findViewById(R.id.grocery_item_name);
t.setText("Something");
}
編輯:這是適配器類
代碼來調用適配器:
adapter = new CustomList(this,R.layout.listitems_improved,Items);
listview.setAdapter(adapter);
private class CustomList extends ArrayAdapter{
ArrayList<Item> items;
Activity myActivity;
LayoutInflater layoutinflater;
View myview;
public ProductsCustomList(Context context, int resource, ArrayList<item> i) {
super(context, resource, p);
this.items = i;
this.myActivity = (Activity) context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//Inflate the custom row layout in the view
layoutinflater = myActivity.getLayoutInflater();
myview = layoutinflater.inflate(R.layout.groceryitems_custom_listview, null);
//instantiate the views in custom row layout
TextView tv = (TextView) myview.findViewById(R.id.tv);
tv.setText(items.get(position).getItemName());
return myview;
}
}
當我打電話給這條線t.setText("Something");
textview不會在ListView中更改,沒有任何反應。爲什麼它不在這裏?
打印裏面是什麼' items.get(position).getItemName()',可能getItemName爲空 – diogojme
't.setText(「Something」);'use' yourAdapter.notifyDataSetChanged();' – diogojme
@diogojme文本已經在ListView中設置了,我想要改變e文本一旦被設置,'getItemName()'方法沒有什麼錯誤 – yousafkh