开发者

how Listview onclick call another activity?

  mListUsers = getUsers();
    lvUsers = (ListView) findViewById(R.id.lv_user);
    lvUsers.setAdapter(new ListAdapter(this, R.id.lv_user, mListUsers));    
    lvUsers.setClickable(true);
    lvUsers.setOnItemClickListener(new AdapterView.OnItemClickListener() 
    {
@Override
       public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) 
        {
            // TODO Auto-generated method stub
             Object o = lvUsers.getItemAtPosition(position);
                UserBO obj = (UserBO) o;
                Toast.makeText(Select.this, "Record Selected= "+obj.getId()+" "+obj.getName()+" "+obj.getEmail()+" "+obj.getContact(), Toast.LENGTH_LONG).show();               

                 Intent intent = new Intent(Select.this,Update.c开发者_如何转开发lass);
                 startActivity(intent);
        }
    });

list_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:padding="6px"
android:orientation="vertical"
android:layout_height="67px" android:id="@+id/rlt_main"
android:background="#E0FFFF" android:clickable="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:orientation="horizontal"
android:layout_height="16px" android:id="@+id/rlt_main"
android:background="#E0FFFF">

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:id="@+id/tv_pid"
    android:text="12" 
    android:layout_centerVertical="true" 
    android:textColor="#E0FFFF" >
 </TextView>
</LinearLayout>

select.xml

<ListView 
android:layout_height="wrap_content" 
android:id="@+id/lv_user" 
android:layout_width="fill_parent"
android:clickable="true"
>

Hi,above code is of onclick listview items selection.but when i click on item from listview nnothing is happening instead i want to call update activity.what is the mistake in my code??if anyone want to see code of XML layout then let me know..


ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View v,int position, long id) {

          Toast.makeText(Context,"Selected item is "+ position, Toast.LENGTH_SHORT).show();    
          Intent i = new Intent(ListActivity.this, SecondActivity.class);     
          ListActivity.this.startActivity(i);

       }
  }


Hi I think you should try like this,

Intent intent = new Intent();
intent.setClassName(Select.this, <packagename>.Update.class.getName());
startActivityForResult(intent,0);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜