2014-11-04 29 views
1

我有我所有的列表視圖項目都出現了這樣的問題: ListView Item barely visible自定義列表視圖項隱約可見

正如你們所看到Hello World!TextView並完美呈現。 但是ListView itens正在顯示他們被禁用。

這是我活動的onCreate方法:

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); 
} 

這是我的自定義適配器:

@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; 

} 

活動佈局

<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> 

和ListView項目佈局:

<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" 
    /> 

+0

list.setClickable(假);你想讓你的列表視圖不可點擊嗎?嘗試刪除此代碼 – 2014-11-04 07:09:04

+1

只需調整您的列表視圖項目的背景和文本顏色。 – Aun 2014-11-04 07:09:36

+0

刪除此list.setClickable(false); list.setEnabled(true); – 2014-11-04 07:11:40

回答

0

我跟着@Aun尖端和解決我的問題。

我只需手動設置所有應用程序的顏色。

0

嘗試。

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

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

<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"/> 

<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" 
    /> 
+0

沒有幫助。在那裏看到我的評論。 – 2014-11-04 08:02:31

+0

k.is你的問題解決了? – 2014-11-04 08:56:04

0

顯示您在AndroidManifest.xml中選定的主題(應用/活動)。我想這是問題所在。

+0

這應該是一條評論。 – 2015-03-12 08:11:58

-1

嘗試這一行 機器人:文字顏色= 「#000000」 在你的TextView

1

我現在已經有點老了,但是我只是偶然發現了這篇文章。

難道是你使用了錯誤的上下文嗎?我想你應該通過你的活動目前情況下,像這樣:

ctx = getContext(); 

或像這樣:

AnswersArrayAdapter adapter = new AnswersArrayAdapter(this, answersList);