Failed to display results Sequentially from BeanClass in Android? - android

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

Related

More than 3 items per sub items GridView Android

I want to display the data from content provider in gridview more than 3 sub items or line
here is my java source code
#Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
players.clear();
// First Check if cursor is not null
if(cursor != null ) {
StringBuilder result = new StringBuilder();
// Now loop to all items and append it to string builder
while (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndex("ID"));
String name = cursor.getString(cursor.getColumnIndex("ITEM_NAME"));
String qty = cursor.getString(cursor.getColumnIndex("QUANTITY"));
String inst = cursor.getString(cursor.getColumnIndex("INSTRUCTION"));
String pid = cursor.getString(cursor.getColumnIndex("POS_ID"));
players.add("Items :" + name + "\n" + "Qty :" + qty + "\n" +
"Details :" + inst + "\n" + " Pos ID :" + pid);
gv.setAdapter(adapter);
resultView.setText(result);
}
} else {
// If cursor is null then display toast amd set empty data.
resultView.setText("Empty data");
Toast.makeText(MainActivity.this, "May be there is no app corresponding to your provider or there is null data.",
Toast.LENGTH_LONG).show();
}
}
the gv.setAdapter(adapter) is where i display the data coming from the content provider
and here is my xml source code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:fillViewport="true"
tools:context="com.condorpos.kitchen_bumpbar.MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<Button
android:id="#+id/btnRetrieve"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:text="#string/show_data" />
<TextView
android:id="#+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clickable="false"
android:padding="5dp"
android:textColor="#000000"
android:textSize="15sp" />
<GridView
android:layout_width="match_parent"
android:layout_height="420dp"
android:numColumns="5"
android:verticalSpacing="140dp"
android:id="#+id/gridView1"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/expListView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="invisible" />
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone"
android:text="#string/empty_list"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"/>
</LinearLayout>
</LinearLayout>
the gridView1 is equals to gv on the java source code i declare it like
Griview gv;
gv=(GridView) findViewById(R.id.gridView1);
from the image below it shows that the data is not fully display looked per column i want to display more than 3 lines but it gives me this result
Any idea or help will do
Thanks a lot guys
You need make height of GridView is match_parent/wrap_content (based on your layout), don't fix size 420dp

How to select all radiobuttons after buttonclick android

I am working on an application where I have multiple linear layouts which are dynamically generated. Each linearlayout has an Id field, Name and a radioGroup containing two radio buttons for Yes and No.
I am also providing a button at bottom of the page so that once the button is clicked, All the YES radio buttons are selected.
How can i achive this as the layout is dynamically generated based on some data:
Here is my layout which is repeated dynamically:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:weightSum="10">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="#+id/RollNum"
android:textSize="20dp"
android:textColor="#color/black"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="6"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Amandeep Singh and some very very long name"
android:gravity="center"
android:id="#+id/Name"
android:textSize="20dp"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:gravity="center">
<RadioGroup
android:id="#+id/radioAttendance"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation='horizontal'
android:gravity="center">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="P"
android:id="#+id/PresentCheck"
android:textSize="10dp"
android:gravity="center"
android:textColor="#color/black"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:id="#+id/AbsentCheck"
android:textSize="15dp"
android:gravity="center"
android:textColor="#color/black"
/>
</RadioGroup>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1">
<View
android:layout_width="fill_parent"
android:layout_height="0.1dp"
android:background="#ffffff" />
</LinearLayout>
</LinearLayout>
I tried following approach but didn't work:
//some code before it for button clicks and all other stuffs
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout scrollViewLinearlayout = (LinearLayout)findViewById(R.id.parent); // The layout inside scroll view
//int count=50;
Studentlist = Arrays.copyOfRange(StudentlistInterim, 1, StudentlistInterim.length);
for(int i = 0; i < Studentlist.length; i++){
String data = Studentlist[i];
String RollNum = data.split("--")[0];
String Name = data.split("--")[1];
Log.d("Name is:", Name);
LinearLayout layout2 = new LinearLayout(context);
layout2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
View item = inflater.inflate(R.layout.item_layout, null, false);
layout2.addView(item);
layout2.setId(i);
TextView trollnum = (TextView) item.findViewById(R.id.RollNum);
trollnum.setText(RollNum);
TextView tname = (TextView) item.findViewById(R.id.Name);
tname.setText(Name);
RadioButton rPresent = (RadioButton)item.findViewById(R.id.PresentCheck);
RadioButton rAbsent = (RadioButton)item.findViewById(R.id.AbsentCheck);
rPresent.setId(i); //tried to set a unique Id for all YES
rAbsent.setId(Studentlist.length+i); // to make the id unique for each YES and NO entry
scrollViewLinearlayout.addView(layout2);
Log.d("Id is: ", trollnum.getText().toString());
}
}
#Override
public void onClick(View v){
switch(v.getId()){
case R.id.bMarkAllPresent:
for (int i=0;i<Studentlist.length;i++){//iterate over the list for the radio buttons
RadioButton r1 = (RadioButton)findViewById(i);
RadioGroup rg = (RadioGroup)findViewById(R.id.radioAttendance);
rg.check(r1.getId()); /* get the id of radio button one by one and mark it checked*/
//Log.d("Button check id:", (r1.getId()));
}
break;
I got 'java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.RadioButton' error in the onClick() method
I am not sure if this approach will work or if this is the best approach.
Please help.
Edit-1:
After using the List way of doing it as per the answer.
RadioButton rPresent = (RadioButton)item.findViewById(R.id.PresentCheck);
RadioButton rAbsent = (RadioButton)item.findViewById(R.id.AbsentCheck);
//rPresent.setId(i);
//rAbsent.setId(Studentlist.length+i); // to make the id unique for each present and absent entry
presentRadioList.add(rPresent); //getting null pointer here
absentRadioList.add(rAbsent);
I am getting null pointer exception.
I suggest keeping two List<RadioButton>s, one for the "yes" selections and one for the "no" selections. Then you can just iterate through the appropriate list.

Adding TextView(s) via java android but inserting blank views

With help of a suggestion from another answer I wrote the below code. But for some odd reason, it displays the text for the first TextView just fine and then, every other TextView below it is a blank! I tried many different ways but unable to figure it out. Someone please assist me..THANKS!
JAVA code(MainActivity.java)
ToDoListDB info = new ToDoListDB(MainActivity.this);
info.open();
String data = info.getData();
info.close();
//Split the List item string into individual strings
String delims = "[\\n]+";
String[] tokens = data.split(delims);
List<TextView> itemList = new ArrayList<TextView>(tokens.length);
for(int i = 0; i < tokens.length; i++)
{
TextView tvItem = new TextView(MainActivity.this);
tvItem.setText(tokens[i]);
tvItem.setTextColor(getResources().getColor(R.color.text_color));
LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
itemList.add(tvItem);
myLayout.addView(itemList.get(i));
//myLayout.addView(tvItem);
//itemList.add(tvItem);
}
XML file
<?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:weightSum="10" >
<EditText
android:id="#+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#DDD"
android:hint="Enter a list item"
android:textColor="#D00" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="8" >
<LinearLayout
android:id="#+id/itemListLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000">
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Button" />
</LinearLayout>
add the layout_orientation in your linearlayout
<LinearLayout
android:id="#+id/itemListLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#000">

Android : Listview of text and Image and the weird scrolling behaviour

In my application I need to create two lists each with different data . I have designed the UI like adding two listviews one after another in a TableLayout within a LinearLayout. I have stored the data in two String arrays and used arrayadapter to populate into the listview.My listview contain a textview and an image.The problem is
1.There is no error shown in the code but the list is getting populated in weird manner. 1st list item is shown, 2nd,3rd,4th list item not shown and 5th is shown 6th not shown, from 7th its fine. When i scroll up, the list is showing all the list items.
2.each list should have its own scrolling control. like if I scroll List "A" ,it should only be scrolled not the List"B" and vice versa. I have attached the code here . Thanks in advance.
mainscreen.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_LinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/request_Table"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#color/black"
android:orientation="vertical"
android:padding="20dp" >
<TableRow
android:id="#+id/request_Row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/blue"
android:orientation="vertical" >
<TextView
android:id="#+id/request_TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="REQUESTS"
android:textColor="#color/white"
android:textStyle="bold" />
<ImageView
android:id="#+id/widget163"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
<TableRow
android:id="#+id/request_Row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/gray"
android:orientation="horizontal" >
<ListView
android:id="#+id/request_ListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:scrollbarAlwaysDrawVerticalTrack="true" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/offered_Table"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#color/black"
android:orientation="vertical"
android:padding="20dp" >
<TableRow
android:id="#+id/offered_Row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/blue"
android:orientation="horizontal" >
<TextView
android:id="#+id/offered_TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="OFFERED"
android:textColor="#color/white"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/offered_Row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ListView
android:id="#+id/offered_ListView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/gray"
android:padding="5dp"
android:scrollbars="vertical"
android:smoothScrollbar="true" />
</TableRow>
</TableLayout>
</LinearLayout>
mainscreen.java
public class MainMenu extends Activity {
RequestAdapter mRequestAdapter;
ListView mListView_req ;
public class RequestData {
int icon;
String list_text;
public RequestData( String mText) {
super();
//this.icon=image;
this.list_text=mText;
}
}
private RequestData[] getListItems(){
Resources mRes = getResources();
String[] sListItems= mRes.getStringArray(R.array.request_list);
int listsize = sListItems.length;
RequestData[] obj = new RequestData[listsize];
int size = obj.length;
for(int i=0; i<size; i++){
obj[i] = new RequestData(sListItems[i]);
}
return obj;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu_screen);
mListView_req= (ListView)findViewById(R.id.request_ListView) ;
mRequestAdapter = new RequestAdapter(this,R.layout.listitem, getListItems());
mListView_req.setAdapter(mRequestAdapter);
}
class RequestAdapter extends ArrayAdapter{
private RequestData rList[]= null;
Context context;
public RequestAdapter(Context context, int textViewResourceId,
RequestData[] data) {
super(context, textViewResourceId, data);
// TODO Auto-generated constructor stub
this.rList= data;
}
#Override
public RequestData getItem(int position){
return rList[position];
}
#Override
public View getView(int pos, View convertView, ViewGroup parent) {
View row= convertView;
if (row== null){
row = getLayoyutinflater().inflate(R.layout.listitem,null);
}
else {
RequestData items = getItem(pos);
TextView text= (TextView) row.findViewById(R.id.List_Text);
if(text!= null){
text.setText(items.list_text);
}
}
return row;
}
listitem.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="150dp">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:id="#+id/text"/>
<ImageView>
android:layout_width="40dp"
android:layout_height="wrap_content"
android:src="#drawable/arrow"
android:layout_marginRight="10dp"/>
</LinearLayout>

Custom SimpleCursorAdapter not displaying data on screen

I've read and tried a dozen solutions from this forum but none of them seem to work - I cannot display data on my lists - view.findViewById(resourceid) returns null each time in bindView - for example when using TextView t = (TextView) view.findViewById(R.id.leftCell). It is strange behaviour considering i have no errors in Logcat, and the view itself isn't null. What am I doing wrong?
I've divided my layout as follows: two LinearLayouts each wrapping a ListView. I've defined a custom row structure for both lists, found in database_item.xml and list_item.xml.
Here's my code.
Main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/topFrame">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Devices loaded from Database: "></TextView>
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView android:text="Name"
android:padding="3dip"
android:gravity="center"/>
<TextView android:text="Remote Address"
android:padding="3dip"
android:gravity="center"/>
<TextView android:text="Type"
android:padding="3dip"
android:gravity="center"/>
</TableRow>
</TableLayout>
<ListView android:id="#+id/databaseList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
</ListView>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.2"
android:id="#+id/bottomFrame">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Detected Xbee nodes via 'introduce' command:"></TextView>
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView android:text="Address"
android:padding="3dip"
android:gravity="center"/>
<TextView android:text="Type"
android:padding="3dip"
android:gravity="center"/>
</TableRow>
</TableLayout>
<ListView android:id="#+id/detectedNodesList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
</LinearLayout>
database_item.xml:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:id="#+id/checkBox"></CheckBox>
<TextView android:id="#+id/topLeftCell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:gravity="center"></TextView>
<TextView android:id="#+id/topCenterCell"
android:padding="3dip"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView android:id="#+id/topRightCell"
android:gravity="center"
android:padding="3dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</TableRow>
</TableLayout>
list_item.xml:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
<TextView android:id="#+id/leftCell"
android:padding="3dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView android:id="#+id/rightCell"
android:gravity="left"
android:padding="3dip"
android:text="TESTING"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</TableRow>
Relevant code from onCreate:
ListView topList = (ListView) findViewById(R.id.databaseList);
ListView bottomList = (ListView) findViewById(R.id.detectedNodesList);
String[] topColumns = new String[] {"name", "my", "type"};
String[] bottomColumns = new String[] {"my","type"};
int[] toTop = new int[] { R.id.topLeftCell, R.id.topCenterCell, R.id.topRightCell};
int[] toBottom = new int[] { R.id.leftCell, R.id.rightCell};
DbCursorAdapter e = new DbCursorAdapter(this, R.layout.database_item, cursor, topColumns, toTop);
DbCursorAdapter d = new DbCursorAdapter(this, R.layout.list_item, cursor, bottomColumns, toBottom);
topList.setAdapter(e);
bottomList.setAdapter(d);
and DbCursorAdapter.java:
public class DbCursorAdapter extends SimpleCursorAdapter {
private Context context;
private int layout;
private final String TAG = "DbCursorAdapter";
LayoutInflater inflater;
public DbCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to) {
super(context,layout,c,from,to);
this.context = context;
this.layout = layout;
inflater = LayoutInflater.from(context);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = inflater.inflate(layout, parent, false);
return v;
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
Cursor c = cursor;
if (layout == R.layout.list_item) {
int addressCol = c.getColumnIndex("my");
int typeCol = c.getColumnIndex("type");
int address = c.getInt(addressCol);
int type = c.getInt(typeCol);
TextView t = (TextView) view.findViewById(R.id.leftCell);
TextView t2 = (TextView) view.findViewById(R.id.rightCell);
if (t != null) {
t.setText(Integer.toString(address));
}
if (t2 != null) {
t2.setText(Integer.toString(type));
}
}
if (layout == R.layout.database_item) {
int nameCol = c.getColumnIndex("name");
int addressCol = c.getColumnIndex("my");
int typeCol = c.getColumnIndex("type");
String name = c.getString(nameCol);
int my = c.getInt(addressCol);
int type = c.getInt(typeCol);
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox);
checkBox.setVisibility(CheckBox.VISIBLE);
TextView t = (TextView) view.findViewById(R.id.topLeftCell);
TextView t2 = (TextView) view.findViewById(R.id.topCenterCell);
TextView t3 = (TextView) view.findViewById(R.id.topRightCell);
if (t != null) {
t.setText(name);
}
if (t2 != null) {
t2.setText(Integer.toString(my));
}
if (t3 != null) {
t3.setText(Integer.toString(type));
}
}
}
if (layout == R.layout.list_item)
The right way to access a resource id is
int list_item_id = context.getResources.getIdentifier(list_item,"layout", getPackageName());
if (layout == list_item_id)
this will return you the resource id of R.layout.list_item . I wanted to just let you know, but i don't know if this is the exact problem.
Much like Yashwanth, my intuition is telling me something is up with if(layout==R.layout.list_item). Have you considered just using separate adapters for each list?
Solved. The problem seemed to be in main.xml:
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView android:text="Name"
android:padding="3dip"
android:gravity="center"/>
<TextView android:text="Remote Address"
android:padding="3dip"
android:gravity="center"/>
<TextView android:text="Type"
android:padding="3dip"
android:gravity="center"/>
</TableRow>
</TableLayout>
Somehow covered the ListView that was supposed to be below it for both the top frame and the bottom frame. Removing TableLayout shows both lists just fine.
Would anybody be able to explain why?

Categories

Resources