我有一個ListAdapter包含一個字符串數組。ListView onItemClick不工作
當我點擊列表中的任何項目時,我希望應用程序將當前點擊的項目傳遞給另一個活動並轉到另一個活動。
我想設置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) {
}
}
也許addNewBuisness.setClickable(真)可以幫助? – 2012-08-05 19:05:43