我有一个包含字符串数组的 ListAdapter。
当我单击列表中的任何项目时,我希望应用程序将当前单击的项目传递给另一个活动并转到另一个活动。
我正在尝试设置 onItemClickListener 但没有成功。
活动:
package com.nituach.nituach;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class NituachActivity extends Activity implements OnClickListener,
OnItemClickListener {
Button addNewBuisness;
ListView blv;
public static int bname;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String TAG = NituachActivity.class.getSimpleName();
addNewBuisness = (Button) findViewById(R.id.btnAddNewBuisness);
addNewBuisness.setOnClickListener(NituachActivity.this);
blv = (ListView) findViewById(R.id.listView1);
Log.d(TAG, "All Variables was created");
DataBase dbc = new DataBase(NituachActivity.this);
dbc.open();
List<String> cs = dbc.getData();
blv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, cs));
dbc.close();
blv.setOnItemClickListener(NituachActivity.this);
}
public void onClick(View v) {
if (v == addNewBuisness) {
Intent addnbIntent = new Intent(NituachActivity.this,
AddNewBuisness.class);
NituachActivity.this.startActivity(addnbIntent);
}
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
}