我有一个带有十个名字的ListView。我想在点击某个名称时使用自定义提醒,并且希望它可以进行编辑。在这段代码中,我只获取ListView,而不是自定义警报。列表视图使用自定义提醒并在android中编辑名称
public class MainActivity extends Activity {
public ListView mainListView;
public ArrayAdapter listAdapter;
final Context context = this;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the ListView resource.
mainListView = (ListView) findViewById(R.id.mainListView);
// Create and populate a List of planet names.
String[] planets = new String[] { "Allu", "Abin", "Bibin", "Aswathy",
"Jibin", "Saran", "Jobin", "Neethu","ammu","Ram"};
ArrayList planetList = new ArrayList();
planetList.addAll(Arrays.asList(planets));
// Create ArrayAdapter using the planet list.
listAdapter = new ArrayAdapter(this, R.layout.simplerow, planetList);
/*// Add more planets. If you passed a String[] instead of a List
// into the ArrayAdapter constructor, you must not add more items.
// Otherwise an exception will occur.
listAdapter.add("Ceres");
listAdapter.add("Pluto");
listAdapter.add("Haumea");
listAdapter.add("Makemake");
listAdapter.add("Eris");*/
// Set the ArrayAdapter as the ListView’s adapter.
mainListView.setAdapter(listAdapter);
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Alert Dialog With EditText"); //Set Alert dialog title here
alert.setMessage("Edit Your Name Here"); //Message here
// Set an EditText view to get user input
final EditText input = new EditText(context);
alert.setView(input);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// You will get as string input data in this variable.
// here we convert the input to a string and show in a toast.
String srt = input.getEditableText().toString();
Toast.makeText(context,srt,Toast.LENGTH_LONG).show();
}
});
//End of alert.setPositiveButton
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
}); //End of alert.setNegativeButton
AlertDialog alertDialog = alert.create();
alertDialog.show();
}
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
});
}
}
尝试打开然后用cliecked和update来更新列表项的所有值。 – 2015-02-24 07:51:26
将“Allu”,“Abin”,“Bibin”,“Aswathy”, “Jibin”,“Saran”,“Jobin”,“Neethu”,“ammu”,“Ram” “,”Bibin“,”Aswathy“, ”吉宾“,”Saran“,”Jobin“,”Neethu“,”ammu“,”Ram“(您不使用双重quoates.Please更改所有符号为双引号) – user3515851 2015-02-24 08:10:35