我正在尝试从 listView 中获取一个对话框。我想让用户看到一个具有 3 种字体大小的对话框,以便他可以更改应用程序的字体大小。要进入此对话框,用户必须点击 listView 中的按钮。我是这样设计的:
package com.reekapps.simplenote;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Dialog;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Settings extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
getActionBar().setTitle("Settings");
String[] listItems = {"Colour", "Font Size",};
ListView lv = (ListView) findViewById(R.id.settings_list);
lv.setAdapter(new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, listItems));
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View
view, int position, long id)
{
String[] listItems = {"Colour", "Font Size",};
if(listItems[position].equals("Font Size"))
{
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Choose Font Size");
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
}
});
// TODO Auto-generated method stub
}
}
它没有显示任何错误,但是当我单击字体大小(进入对话框的按钮)时它会崩溃。
感谢您的时间!