如何从listview项目移动到android中的其他布局.......
我试图通过点击它从listview移动到其他布局帮助我plz
public class ListViewActivity extends Activity {
private ListView lv1;
private String lv_arr[] = {"Android", "iPhone", "BlackBerry", "Nokia"};
@Override
public void onCreate(Bundle x)
{
super.onCreate(x);
setContentView(R.layout.activity_main);
lv1=(ListView)findViewById(R.id.ListView01);
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));
//lv1.setTextFilterEnabled(true);
lv1.setOnItemClickListener(new OnItemClickListener() {
}
}
}
答案 0 :(得分:0)
使用onItemClickListener。
这很简单。如果你搜索周围你会得到这个。
List.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(getApplicationContext(),SecondClass.class);
intent.putExtra("passsomething","value_of_variable");
startActivity(intent);
}
});
答案 1 :(得分:0)
尝试以下
lv1.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,int position, long arg3)
{
Intent i = new Intent(ActivityName.this,SecondActivity.class);
// if you just want to navigate to second activity remove the below lines
//String value = (String) arg0.getItemAtPosition(position);
//i.putExtra("key",value);
startActivity(i);
});
在SecondActivity中
如果要在第二个活动中显示listview中单击的项目,请使用textview,否则忽略下面的
Bundle extras = getIntent().getExtras();
if(extras!=null)
{
String value = extras.getString("key");
// textview.setText(value);
}