问题
i am getting data from database and putting it in Imageview now i am getting two id from DB i.e. 2 and 3 first it will set image of id 2 in imageview which is working fine and then next step is it will get questions related to that id from another function while its not doing its first extracting id 2 and id 3 then calling function for id = 3 but i snt want this...How can i overcome on this problem ? 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);
}
here is the 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>
METHOD:
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;
}
来源:https://stackoverflow.com/questions/21958529/failed-to-display-results-sequentially-from-beanclass-in-android