-2

如何从列表视图项移动到 android 中的其他布局.......

我试图通过单击从列表视图移动到其他布局,请帮助我

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() {

        }
    }
}
4

2 回答 2

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);

        }
    });
于 2013-09-02T10:24:44.840 回答
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

如果您想在第二个活动中显示在列表视图中单击的项目,请使用文本视图,否则请忽略以下内容

Bundle extras = getIntent().getExtras();
if(extras!=null)
{
     String value = extras.getString("key");
     // textview.setText(value);
}  
于 2013-09-02T10:25:47.337 回答