繁体   English   中英

由java.lang.UnsupportedOperationException引起:AdapterView不支持addView(View,layoutParams)

[英]Caused by java.lang.UnsupportedOperationException: addView(View,layoutParams) is not supported in the AdapterView

我收到以下异常[由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:AdapterView中不支持addView(View,LayoutParams)。

无法找出问题所在,请帮忙! 提前致谢!

主要错误是因为AdapterView下的TextView。 实际上应该在AdapterView下没有任何视图,删除TextView解决了问题..! :d

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM