gpt4 book ai didi

java - 引起的java.lang.UnsupportedOperationException : addView(View,layoutParams)在AdapterView中不受支持

转载 作者:行者123 更新时间:2023-12-02 07:07:05 26 4
gpt4 key购买 nike

我在下面的代码 fragment 中收到以下异常[由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:unable to start activity component info{ be.droid.medminder/be.bedroid.medminder.MedReminderActivity}:java.lang.UnsupportedOperationException:addView (View,LayoutParams)is not supported in AdapterView.

不知道问题出在哪里,请帮忙!提前致谢!

最佳答案

主要错误是由于 AdapterView 下的 TextView 引起的。实际上 AdapterView 下不应该有任何 View ,删除 TextView 解决了问题..! :D

关于java - 引起的java.lang.UnsupportedOperationException : addView(View,layoutParams)在AdapterView中不受支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15975397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com