0
我有這樣的陣列對話消息不起作用
String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows8", "Max OS X", "Linux", "OS/2" };
我需要顯示ListView和適配器,當我點擊對話框消息的一些元素,我需要顯示元素被點擊了什麼上的元素。
public class zadaca1 extends ListActivity {
String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows8", "Max OS X", "Linux", "OS/2" };
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.layout_zadaca1);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,values));
ListView listView=getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AlertDialog.Builder builder= new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Delete entry");
builder.setMessage("Are you sure you want to delete this entry?");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
dialog.cancel();
}
});
// builder.setMessage(((TextView)view).getText());
builder.show();
}
});
}
}
但是當我在我的手機上運行,然後單擊某個項目它說不幸zadaca1已停止。
我也嘗試
AlertDialog.Builder builder= new AlertDialog.Builder(this);
和
AlertDialog.Builder builder= new AlertDialog.Builder(AlertDialog.Builder.this);
但是這個代碼顯示錯誤
'對話框消息不work'定義**不工作**。 '這段代碼顯示錯誤**,**錯誤?請問LogCat? – 2015-02-07 12:22:36
in logcat錯誤是什麼是顯示帖子logcat信息 – Hanuman 2015-02-07 12:26:16
嘗試'AlertDialog.Builder builder = new AlertDialog.Builder(zadaca1.this);' – ved 2015-02-07 13:01:17