0

问题是在微调器中选择的项目以白色呈现,尽管我已经明确设置了颜色。我不知道该怎么做。我用谷歌搜索了类似的主题,但通过设置颜色解决了它们。对我来说没有帮助。这是我的代码:

private View getFormView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater inflater = mA.getLayoutInflater();
        v = inflater.inflate(R.layout.f_new_program_form, null);
        Spinner sp = (Spinner) v.findViewById(R.id.spinnerExercises);
        ExerciseSpinnerAdapter spAdapter = new ExerciseSpinnerAdapter(mA);

        LoadTask task = new LoadTask((BBBaseAdapter) spAdapter,
                URLs.host + URLs.allExercisesUrl, mA);
        task.execute();
        sp.setAdapter(spAdapter);
    }
    return v;
}

练习SpinnerAdapter.java:

public class ExerciseSpinnerAdapter extends BBBaseAdapter implements
    SpinnerAdapter {

protected JSONArray data = new JSONArray();

public ExerciseSpinnerAdapter(Activity a) {
    super(a);
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return this.data.length();
}

@Override
public JSONObject getItem(int position) {
    try {
        return this.data.getJSONObject(position);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public int getItemViewType(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        v = mA.getLayoutInflater().inflate(R.layout.custom_spinner, parent,
                false);

    }
    TextView t = (TextView) v.findViewById(R.id.spinnerTextZZ);
    try {
        t.setText(getItem(position).getString("name"));
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     t.setTextColor(Color.RED);

    return v;
}

@Override
public int getViewTypeCount() {
    // TODO Auto-generated method stub
    return 1;
}

@Override
public boolean hasStableIds() {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean isEmpty() {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void registerDataSetObserver(DataSetObserver observer) {
    // TODO Auto-generated method stub

}

@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
    // TODO Auto-generated method stub

}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        v = mA.getLayoutInflater().inflate(R.layout.custom_spinner, parent,
                false);

    }
    TextView t = (TextView) v.findViewById(R.id.spinnerTextZZ);
    try {
        t.setText(getItem(position).getString("name"));
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     t.setTextColor(Color.RED);
    return v;
}

@Override
public void updateEntries(Object data) {
    this.data = (JSONArray) data;
    notifyChanges();
}   

public void notifyChanges() {
    notifyDataSetChanged();
}

}

custom_spinner:

 < TextView xmlns:android="http://schemas.android.com/apk/res/android" 
   android:id="@+id/spinnerTextZZ"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:padding="0dp"
   android:layout_margin="0dp"
   android:text="!"
   android:textAppearance="?android:attr/textAppearanceMedium" android:textColor = "#000000" />

我错过了什么?

4

1 回答 1

0

如果你有我有的额外方法:

@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 1;
}

@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}

@Override
public void registerDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub

}

删除它们或实施。但是如果你扩展 BaseAdapter 它们已经实现了。不知道我从哪个例子中得到它们。

于 2013-02-20T21:30:55.023 回答