Closed oliguo closed 9 years ago
我嘗試在initView尾添加
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView textView=(TextView)view.findViewById(R.id.list_item_text); Toast.makeText(view.getContext(),textView.getText(), Toast.LENGTH_SHORT); } });
代碼:
private void initView() { mHandler = new Handler(); mListView = (XListView) findViewById(R.id.list_view); mListView.setPullRefreshEnable(true); mListView.setPullLoadEnable(true); mListView.setAutoLoadEnable(true); mListView.setXListViewListener(this); mListView.setRefreshTime(getTime()); mAdapter = new ArrayAdapter(this, R.layout.vw_list_item, items); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView textView=(TextView)view.findViewById(R.id.list_item_text); Toast.makeText(view.getContext(), textView.getText(), Toast.LENGTH_SHORT); } }); }
希望實現點擊對應item時獲取對應內容,運行后發現沒有觸發成功,請教下是不是思路哪裡有錯,謝謝
原來漏了show,馬虎了。。。。。
Toast.makeText(view.getContext(), textView.getText(), Toast.LENGTH_SHORT).show();
OK. closed issue.
我嘗試在initView尾添加
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView textView=(TextView)view.findViewById(R.id.list_item_text); Toast.makeText(view.getContext(),textView.getText(), Toast.LENGTH_SHORT); } });
代碼:
private void initView() { mHandler = new Handler(); mListView = (XListView) findViewById(R.id.list_view); mListView.setPullRefreshEnable(true); mListView.setPullLoadEnable(true); mListView.setAutoLoadEnable(true); mListView.setXListViewListener(this); mListView.setRefreshTime(getTime()); mAdapter = new ArrayAdapter(this, R.layout.vw_list_item, items);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView textView=(TextView)view.findViewById(R.id.list_item_text);
Toast.makeText(view.getContext(), textView.getText(), Toast.LENGTH_SHORT);
}
});
}
希望實現點擊對應item時獲取對應內容,運行后發現沒有觸發成功,請教下是不是思路哪裡有錯,謝謝