Search code examples
androidandroid-listviewlistviewitem

Custom ListView Item barely visible


I'm having a problem that all my ListViews Items are showing like this: ListView Item barely visible

As you guys can see Hello World! is a TextView and is showing perfectly. But the ListView itens are showing like they are disabled.

This is my Activity's onCreate method:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_open_answers);

    ctx = getApplicationContext();
    Intent intent = getIntent();
    usersurvey_id = intent.getIntExtra("usersurvey_id", -1);

    list = (ListView) findViewById(R.id.listview_answers);

    getAnswers();

    AnswersArrayAdapter adapter = new AnswersArrayAdapter(ctx, answersList);
    list.setAdapter(adapter);
    list.setClickable(false);
    list.setEnabled(true);
}

This is my Custom Adapter:

    @Override
public View getView(int position, View convertView, ViewGroup parent){
    Answers answerItem = answersList.get(position);
    ViewHolder holder;

    if(convertView == null){
        LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.listitem_answers, null);
        holder = new ViewHolder();

        holder.question = (TextView) convertView.findViewById(R.id.tv_texto_pergunta);
        holder.answer = (TextView) convertView.findViewById(R.id.tv_texto_resposta);

        convertView.setTag(holder);
    }else{
        holder = (ViewHolder) convertView.getTag();
    }

    holder.question.setText(getQuestionById(answerItem.getAnswer_question_id()));
    holder.answer.setText(answerItem.getAnswer_answer());

    return convertView;

}

Activity layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.seven.questionario.OpenAnswers">

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<ListView
    android:id="@+id/listview_answers"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

</ListView>

And ListView Item Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/tv_pergunta"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:text="Pergunta:"
    android:background="#D0D0D0"/>

<TextView
    android:id="@+id/tv_texto_pergunta"
    android:layout_width="fill_parent"
    android:layout_height="60sp"
    android:layout_below="@id/tv_pergunta"
    android:text="Texto da pergunta"
    android:background="#D0D0D0"/>

<View
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/tv_texto_pergunta"
    android:background="@drawable/dotted"
    />

<TextView
    android:id="@+id/tv_resposta"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/tv_texto_pergunta"
    android:text="Resposta:"
    android:textStyle="bold"/>

<TextView
    android:id="@+id/tv_texto_resposta"
    android:layout_width="fill_parent"
    android:layout_height="80sp"
    android:layout_below="@id/tv_resposta"
    android:text="Texto da resposta" />
<View
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/back"
    android:layout_below="@id/tv_texto_resposta"
    />


Solution

  • I followed @Aun tip and solved my problem.

    I just had to set manually all my app's colors.