0

i need to create a widget with listview for my android application. so that i searched in google and i found one link taht is below.

https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget/LoremWidget

and i followed the mentioned above link. everything is working perfectly. but i cant print the sub items of the listview.

Widget_Layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:gravity="top"
   tools:context=".MainActivity"
   android:background="@drawable/widget_frame" >
<ListView
  android:id="@+id/listItem"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginTop="45dp"
  android:cacheColorHint="#00000000"
  android:background="@drawable/widget_frame"
/>
</RelativeLayout>

This is the layout for the items of the ListView

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:textSize="20dp"
android:minHeight="?android:attr/listPreferredItemHeight"/>

here is the getViewAt(int position) function where we print all items in listview. i printed the sub items of items using '+' operator and '\n'. but i cant differentiate items and its sub items that means i cant give specific properties to sub items. can anybody please help me to differentiate the sub items from items.

getViewAt

    public RemoteViews getViewAt(int position) {
    RemoteViews row=new RemoteViews(mCtxt.getPackageName(),R.layout.widget_layout);
    row.setTextViewText(android.R.id.text1, Names[position]+"\n"+address[position]);
    }
user3546693
  • 364
  • 3
  • 18

1 Answers1

0

You should inflate another listview. So you can take subListView position , to get child elements.

You can find a good solution in there https://stackoverflow.com/a/11653149/210973

Community
  • 1
  • 1
Megawolt
  • 589
  • 5
  • 19
  • Is there any other way like row.setTextzviewText? @Megawolt – user3546693 Apr 16 '15 at 07:54
  • May be you can iterate **Names[position]** `string names = Names[position]+"\n"+address[position]; for (FooModel item : Names[position]) { names += item.surname; } row.setTextViewText(android.R.id.text1, names);` – Megawolt Apr 16 '15 at 08:10