我收到以下异常[由java.lang.UnsupportedOperationException引起:下面的代码片段中的AdapterView中不支持addView(View,layoutParams)]。
public class MedReminderActivity extends ListActivity {
private static final String[] MEDS = new String[] { "Dafalgan", "Citrozone" };
private ProgressDialog mProgressDialog = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// setContentView(R.layout.main);
Cursor c = null;
ListAdapter cursorListAdapter = new SimpleCursorAdapter(this, R.layout.list_item_my_medicines, c, new String[] { "name" }, new int[] { R.id.list_name });
ListAdapter listAdapter = new ArrayAdapter<String>(this, R.layout.list_item_my_medicines, MEDS);
setListAdapter(listAdapter);
OnClickListener testButton = new OnClickListener() {
public void onClick(View v) {
Cursor cursor = getContentResolver().query(MedicineContentProvider.CONTENT_URI, new String[] { Reminder.ID, "name", "method" }, "name LIKE ?", new String[] { "%2%" }, null);
List<Medicine> medicines = MedicineMapper.mapCursorToMedicines(cursor);
cursor = getContentResolver().query(ReminderContentProvider.CONTENT_URI, new String[] { Medicine.ID, "medicine_id", "time" }, null, null, null);
List<Reminder> reminders = ReminderMapper.mapCursorToReminders(cursor);
}
};
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(testButton);
// OnClickListener testButton = new OnClickListener() {
// public void onClick(View v) {
// Cursor cursor =
// getContentResolver().query(MedicineContentProvider.CONTENT_URI, new
// String[] { Reminder.ID, "name", "method" }, "name LIKE ?", new
// String[] { "%2%" }, null);
//
// List<Medicine> medicines =
// MedicineMapper.mapCursorToMedicines(cursor);
//
// cursor =
// getContentResolver().query(ReminderContentProvider.CONTENT_URI, new
// String[] { Medicine.ID, "medicine_id", "time" }, null, null, null);
//
// List<Reminder> reminders =
// ReminderMapper.mapCursorToReminders(cursor);
// }
// };
//
// Button button = (Button) findViewById(R.id.button1);
// button.setOnClickListener(testButton);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.alarmMenu:
startActivity(new Intent(this, AlertTestLauncher.class));
return true;
case R.id.settingsMenu:
Intent intent = new Intent(this, EditPreferencesActivity.class);
startActivity(intent);
return true;
case R.id.medsMenu:
startActivity(new Intent(this, MedsActivity.class));
return true;
case R.id.remindersMenu:
startActivity(new Intent(this, RemindersActivity.class));
return true;
case R.id.smartMenu:
startActivity(new Intent(this, SmartPreferencesActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onProgressUpdate(String... args) {
// here you will have to update the progressbar
// with something like
mProgressDialog.setProgress(Integer.parseInt(args[0]));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
// Toast.makeText(this, "klik op item " + position,
// Toast.LENGTH_LONG).show();
Intent i = new Intent(this, MedDetailActivity.class);
i.putExtra("medname", MEDS[position]);
startActivity(i);
super.onListItemClick(l, v, position, id);
}
}
java.lang.RuntimeException:无法启动活动组件信息{ be.droid.medminder / be.bedroid.medminder.MedReminderActivity}:java.lang.UnsupportedOperationException:addView AdapterView中不支持(View,LayoutParams)。
无法确定问题所在,请帮忙!在此先感谢!
答案 0 :(得分:2)
主要错误是因为AdapterView下的TextView。实际上应该在AdapterView下没有任何视图,删除TextView解决了问题..! :d