本文介绍了在ListView控件事件单击(扩展ListActivity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个code,但我看不到的动作时,我从列表中选择一个项目点击。
这code显示我的ArrayList中profilesArrayList的信息,但我不知道我怎么查我正在选择什么项目形成列表视图。任何人都可以帮我吗?
profilesArrayList =新的ArrayList<&档案GT;();
profilesArrayList = copyProfilesToArrayList();
ProfileAdapter适配器=新ProfileAdapter(
getApplicationContext(),R.layout.profiles_item,profilesArrayList); listViewProfiles =(ListView控件)findViewById(android.R.id.list);
listViewProfiles.setAdapter(适配器); listViewProfiles.setOnItemClickListener(新OnItemClickListener(){ @覆盖
公共无效onItemClick(适配器视图<>一种,视图V,INT位置,长的id){
开关(位置){
情况下0: Log.d(cardNumber,profilesArrayList.get(0).getCardNumber()); 打破;
解决方案
如果该code你的容器类是ListActivity,只是覆盖onListItemClick为类,而不是将其设置为视图的OnItemClickListener。这对我的作品
公共类ProfileList文件扩展ListActivity
{
私人的ArrayList<&档案GT; profilesArrayList;
@覆盖
公共无效的onCreate(捆绑savedInstanceState)
{
super.onCreate(savedInstanceState);
//填充您的ArrayList setListAdapter(新ArrayAdapter<&档案GT;());
} @覆盖
保护无效onListItemClick(ListView中升,视图V,INT位置,长的ID)
{
super.onListItemClick(L,V,位置ID);
Log.d(cardNumber,profilesArrayList.get(位置).getCardNumber());
}
}
i have this code but i can't see the action when i click on a item from the list.This code shows me the info on ArrayList profilesArrayList but i dont know how i check what item i am selecting form the listview. Anyone can help me?
profilesArrayList = new ArrayList<Profile>();
profilesArrayList = copyProfilesToArrayList();
ProfileAdapter adapter = new ProfileAdapter(
getApplicationContext(), R.layout.profiles_item, profilesArrayList);
listViewProfiles = (ListView)findViewById(android.R.id.list);
listViewProfiles.setAdapter(adapter);
listViewProfiles.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
switch(position) {
case 0:
Log.d("cardNumber", profilesArrayList.get(0).getCardNumber());
break;
解决方案
If your container class for this code is the ListActivity, just override the onListItemClick for that class, rather than set it as an OnItemClickListener for the view. That works for me
public class ProfileList extends ListActivity
{
private ArrayList<Profile> profilesArrayList;
@Override
public void onCreate ( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
//populate your arraylist
setListAdapter ( new ArrayAdapter<Profile>() );
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
Log.d("cardNumber", profilesArrayList.get(position).getCardNumber());
}
}
这篇关于在ListView控件事件单击(扩展ListActivity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!