在android中单击listview项时打开活动时出错

时间:2015-08-05 03:42:13

标签: android listview android-listview

我想在点击listview项目

时打开活动
 listView.setOnItemClickListener(new ItemClickEvent());

这是类 ItemClickEvent

class ItemClickEvent implements AdapterView.OnItemClickListener {

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        if (mBluetoothAdapter.getState() != BluetoothAdapter.STATE_ON) {
            Toast.makeText(MainActivity.this, "Bluetooth not enable",
                    Toast.LENGTH_SHORT).show();
            return;
        }
        if (mBluetoothAdapter.isDiscovering())
            mBluetoothAdapter.cancelDiscovery();
        Intent i = new Intent(MainActivity.this, DetailItemActivity.class);
        startActivity(i);

    }

这是类 DetailItemActivity

public class DetailItemActivity extends Activity {

TextView tv1, tv2,tv3,tv4;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.abcd);

}

}

我创建了abcd.xml但是当我点击listview项时,它无法正常工作。

1 个答案:

答案 0 :(得分:0)

只需在DetailItemActivity类中添加接收Intent: -

Intent intent = getIntent();