我从数据库获取数据并将其放入Imageview现在我从DB获得两个id,即2和3首先它将在imageview中设置id 2的图像,这是正常工作然后下一步是它会得到相关的问题来自另一个函数的那个id虽然它没有做第一次提取id 2和id 3然后调用id = 3的函数但是我想要这个......我怎么能克服这个问题呢? 的 CODE
TableLayout questionHeadingTableLayout;
questionHeadingTableLayout = (TableLayout) findViewById(R.id.questions_table);
for(int i=0;i<topicBeanList.size();i++)
{
final TableRow questionHeadingTableRow = (TableRow) inflator.inflate(
R.layout.questions_table_row, null);
LinearLayout questionHeadingLayout = (LinearLayout)questionHeadingTableRow.findViewById(R.id.question_heading_layout);
LinearLayout questionsLayout = (LinearLayout)questionHeadingTableRow.findViewById(R.id.question_layout);
TopicBean topicBean = topicBeanList.get(i);
Log.i("GetSubtopicsForTopic","");
Log.i("getTopicImageName",""+topicBean.getTopicImageName());
Log.i("getTopicId",""+topicBean.getTopicId());
questionHeadingLayout.setVisibility(View.VISIBLE);
questionsLayout.setVisibility(View.GONE);
ImageView questionHeadingImage = (ImageView)questionHeadingTableRow.findViewById(R.id.question_heading_imageview);
questionHeadingImage.setImageBitmap(getBitmapFromAsset(topicBean.getTopicImageName()));
ArrayList<QuestionBean> questionBeanList = AndroidUtil.externalDb.GetQuestions(topicBeanList.get(i).getTopicId());
Log.i("questionBeanList size",""+questionBeanList.size());
questionHeadingTableLayout.addView(questionHeadingTableRow);
}
这是xml:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/questions_rowlayout"
android:orientation="vertical"
android:background="@color/white">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/top_bar"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/question_heading_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="7dp"
android:visibility="visible">
<ImageView
android:id="@+id/question_heading_imageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="2dp"
android:clickable="false"
android:layout_marginRight="2dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/question_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:visibility="gone"
>
<TableLayout
android:id="@+id/questiontable_tablelayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_below="@+id/question_heading_layout"
></TableLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</TableRow>
方法:
public ArrayList<QuestionBean> GetQuestions(int id)
{
ArrayList<QuestionBean> questionBeanList = new ArrayList<QuestionBean>();
String questionQuery = "SELECT * FROM question WHERE topic_id="+id+"";
Cursor cursor = database.rawQuery(questionQuery, null);
Log.i("Cursor questionQuery Print:",""+questionQuery);
if(cursor != null) {
cursor.moveToFirst();
while(!cursor.isAfterLast()) {
Log.d("cursor",""+cursor);
QuestionBean questionBean = new QuestionBean();
questionBean.setQuestionId(cursor.getInt(0));
questionBean.setQuestionTopicId(cursor.getInt(1));
questionBean.setQuestionImageName(cursor.getString(2));
Log.i("cursor QuestionId",""+cursor.getInt(0));
Log.i("cursor QuestionTopicId",""+cursor.getInt(1));
Log.i("cursor QuestionImageName",""+cursor.getString(2));
questionBeanList.add(questionBean);
cursor.moveToNext();
}
} else {
Log.d("", "Cursor is Null");
Log.d("retrieving all parameters", "count < 0");
}
cursor.close();
return questionBeanList;
}