我已經做了線性佈局和添加視圖,但是,視圖出現兩次,我不知道爲什麼會發生。可以修復它嗎? 我有關於適配器的問題,我看了幾次,我發現這裏沒有什麼奇怪的。但是我刪除了addView語句,它不會出現之前添加過的任何視圖。適配器上的Double AddView
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
// inflater.inflate(R.layout. parent,false);
convertView = inflater.inflate(R.layout.exerciseui_item,parent,false);
}
Exercise question = exercises.get(position);
TextView question_view = (TextView) convertView.findViewById(R.id.exercise_question);
String question_test = question.getOrder() + " " + question.getText() ;
question_view.setText(question_test);
int answer_num = question.getAnswer().size();
LinearLayout linear = (LinearLayout) convertView.findViewById(R.id.exercise_answer);
ExerciseAnswer answer = question.getAnswer().get(0);
int answer_order = answer.getOrder();
String answer_text = answer.getText();
String answer_final = answer_order + " " + answer_text;
TextView answer_view = new TextView(linear.getContext());
answer_view.setPadding(20, 5, 5, 5);
answer_view.setTextSize(30);
answer_view.setText(answer_final);
linear.addView(answer_view);
return convertView;
}
以下是exerciseui_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/exercise_answer" >
<TextView
android:id="@+id/exercise_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13dp"
></TextView>
</LinearLayout>
你如何將視圖添加到線性佈局? – Faizan
我想通過在convertView上查找線性佈局將視圖添加到線性佈局中。然後,我在其上添加視圖 – user1494052