Android ListView RSS Reader on a fragment - android

So.
I'm pretty noob in fragments, and i spent my last days tryin to show a very very simple RSS Reader in an app which has many fragments.
I was following a guide (actually many guides, but this one was the one which had less code.. just for learning purpose: http://www.html.it/pag/19519/android-e-le-applicazioni-di-rete/).
This is the xml about the fragment in which i would to show the RSS Reader (called fragment_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#607D8B"
tools:context=".MainActivity$PlaceholderFragment"
android:id="#+id/main1">
<ImageView
android:id="#+id/newsBanner1"
android:layout_width="wrap_content"
android:layout_height="120sp"
android:layout_marginTop="0dp"
android:gravity="top"
android:layout_marginBottom="10dp"
android:src="#drawable/news_banner"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="News:"
android:id="#+id/newsTitleText1"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginTop="140dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ScrollView
android:id="#+id/scrollerNews1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/newsTitleText1"
android:layout_marginTop="8dp"
android:scrollbars="vertical"
android:fillViewport="true">
<ListView
android:id="#+id/rssListView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</ScrollView>
Yeah it has "main1" id because is the "default" layout fragment at the opening of the app.
And this is the java class
public class NewsFragment extends Fragment {
String feedUrl = "";
ListView rssListView = null;
ArrayList<RSSItem> RSSItems = new ArrayList<RSSItem>();
ArrayAdapter<RSSItem> array_adapter = null;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View setView = inflater.inflate(R.layout.fragment_main, container, false);
feedUrl = "sample_feed_url";
refreshRSSList();
rssListView = (ListView) setView.findViewById(R.id.rssListView);
array_adapter = new ArrayAdapter<RSSItem>(this.getActivity(), R.layout.fragment_main, RSSItems);
rssListView.setAdapter(array_adapter);
refreshRSSList();
return setView;
}
private void refreshRSSList() {
ArrayList<RSSItem> newItems = RSSItem.getRSSItems(feedUrl);
RSSItems.clear();
RSSItems.addAll(newItems);
}
At the moment when i run the app, everything is showed except for the listview (which, i guess, is empty).
Many thanks to whoever will help me :D

When you initialize your array adapter, the layout parameter is wrong. You have mentioned the layout of the fragment. Here it's asking the layout of listview. I mean layout of an item in listview. You need to create a new file in layout and name it as list_item.xml. Define list_item.xml :
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_item_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical">
</TextView>
Now your array adapter will be
array_adapter =new ArrayAdapter(getActivity(),R.layout.list_item,R.id.list_item_textview,rssItems);
You can also use the constructor which you have defined. What I did explicitly mentions id of TextView. You can see the difference here: link. Let me know if it doesn't work.

Related

setOnItemClickListener don't work when overlapping two listviews

I'm doing an app in which the user can switch between two languages (english and French), I have a fragment in which the data is displayed into a listview, but since the data is different depending on the language selected, I overlapped two listviews and made one visible depending on the language selected.
Now the issue that I am facing is that the method onItemClicklistener only works for one listview even though the code is almost identical in both cases. I noticed that in the layout the listview that is written last is the one that have the method working. I would like to know if there was a way around this so that both listviews can have their method working.
here's the code , I omitted certains details to keep it short:
public class ReportFragment extends Fragment {
private ListView listView;
private ListView listView_fr;
public ReportFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_report, container, false);
reportList = new ArrayList<>();
reportList_fr = new ArrayList<>();
listView = view.findViewById(R.id.listView_report);
//Listview for french reports
listView_fr = view.findViewById(R.id.listView_report_fr);
if (Locale.getDefault().getLanguage().contains("en")){
listView_fr.setVisibility(View.GONE);
listView.setVisibility(View.VISIBLE);
} else if (Locale.getDefault().getLanguage().contains("fr")){
listView_fr.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
}
listView.setOnItemClickListener((parent, view1, position, id) -> {
Report report = reportList.get(position);
//Opening the upload file in browser using the upload url
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(report.getUrl()));
Log.d("TAG", "link en: " + Uri.parse(report.getUrl()));
startActivity(intent);
});
listView_fr.setOnItemClickListener((parent, view12, position, id) -> {
Report_fr report = reportList_fr.get(position);
//Opening the upload file in browser using the upload url
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(report.getUrl()));
Log.d("TAG", "link fr: " + Uri.parse(report.getUrl()));
startActivity(intent);
});
return view;
}
}
and the layout:
<?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="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/unicef"
android:orientation="vertical"
tools:context=".UI.ReportFragment">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_background"
android:gravity="center_horizontal"
android:text="#string/textview_info_report_fragment"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_marginTop="20dp"
android:id="#+id/listView_report_fr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="10.0sp"/>
<ListView
android:layout_marginTop="20dp"
android:id="#+id/listView_report"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="10.0sp"/>
</RelativeLayout>
</LinearLayout>
The problem is that you are using the relative layout in the root element of the listview Instead of that use this code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_marginTop="20dp"
android:id="#+id/listView_report_fr"
android:layout_width="match_parent"
android:layout_height="0dp"
android:weight="1"
android:dividerHeight="10.0sp"/>
<ListView
android:layout_marginTop="20dp"
android:id="#+id/listView_report"
android:layout_width="match_parent"
android:layout_height="0dp"
android:weight="1"
android:dividerHeight="10.0sp"/>
</LinearLayout>

How to programatically add multiple Fragments to activity in android

I am trying to display 6 rows inside a linear layout. I want to do this through fragments as the content will be dynamic and the number of rows will also be dynamic later on. I have the following code but only one row appears on the screen. I have SettingsActivity.java, settings.xml ThemeRowFragment,java and theme_row_layout.xml.
SettingsActivity.java
//imports
public class SettingsActivity extends FragmentActivity {
private int NUM_THEMES = 7;
ThemeRowFragment[] view_themes;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
view_themes = new ThemeRowFragment[NUM_THEMES];
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
for (int i = 0; i < view_themes.length; i++) {
view_themes[i] = new ThemeRowFragment(COLOR_MAP[i]);
fragmentTransaction.add(R.id.theme_linear_layout, view_themes[i],
"Row" + i);
}
fragmentTransaction.commit();
}
}
settings.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/theme_linear_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/string_theme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/string_theme"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#cde21c" />
</LinearLayout>
ThemeRowFragment.java
public class ThemeRowFragment extends Fragment {
private int[] colors;
public ThemeRowFragment(int colors[]) {
super();
this.colors = colors;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.theme_row_layout, container,
false);
return view;
}
}
theme_row_layout.xml
<?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="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/pick_colors" >
</TextView>
</LinearLayout>
Fragments will inflate themselves into the View you add them to. So you really can't do it this way. So you need to have X empty containers, one for each fragment you are going to inflate. Add each fragment to the same container will actually layer them all on top of each other, sort of making them really hard to see and use when the screen renders.
Alternatives:
You could do something like the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/theme_linear_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/string_theme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/string_theme"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#cde21c" />
<FrameLayout android:id="#+id/fragment_container1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout android:id="#+id/fragment_container2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout android:id="#+id/fragment_container3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout android:id="#+id/fragment_container4"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout android:id="#+id/fragment_container5"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<!-- etc. -->
</LinearLayout>
Or just add each FrameLayout programatically via the LinearLayout's addView() with a unique ID for each FrameLayout.
LinearLayout layout = (LinearLayout)findViewById(R.id.linear);
FragmentTxn txn = getFragmentManager.beginTransaction();
int i = 1; // This seems really fragile though
for (Fragment f : fragments) {
FrameLayout frame = new FrameLayout(this);
frame.setId(i);
layout.addView(frame);
txn.add(i, f);
i++;
}
txn.commit();
Or the other way would be to just use a listView and add each row that way. Not using Fragments at all.
<TextView
android:id="#+id/string_theme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/string_theme"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#cde21c" />
<ListView android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
then later on do something like this:
ListView view = (ListView)findViewById(R.id.listview);
view.setAdapter(new ArrayAdapter(items) { // items is a collection of objects you are representing
public View getView(int position, View view, ViewGroup parent) {
view = LayoutInflator.from(parent.getContext()).inflate(R.layout.theme_row_layout, parent, false);
// manipulate the view
return view;
});
You are creating a instance of ThemeRowFragment n number of times. The problem is you are creating this as an fragment and trying to add it dynamically. Since you instantiate the same Fragment i suggest you to use ListView and use a custom adapter and set CustomView and override the getView method of your adapter to adjust your views

How to display multiple number of TextViews inside each row in ListView?

I am creating a Help page in which I have a set of questions and answers. These questions and answers have different styles. Here is the xml file, which describes the layout of a question & answer set:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<TextView
android:text="#string/Help_first_question"
android:id="#+id/text1"
android:padding="5dip"
android:background="#e0f3ff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="#+id/panel1"
android:visibility="gone"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_margin="2dip"
android:text="#string/Help_first_answer"
android:padding="5dip"
android:background="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
I want to display multiple questions and answers within a listView, whereby each row contains a set of the question and the answer. My listview looks like :
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
so it will look like :
first row : Q
A
second row : Q
A
third row : Q
A
What is the best approach for achieving this?
create custom adapter and use the below layout to achieve your goal
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
You need to implement a custom ListAdapter implementing all of the abstract methods.
Let's create a QuestionAndAnswerListAdapter, which you can make your ListView by setting it up in onCreate:
public void onCreate(Bundle savedInstanceState) {
super(savedInstanceState);
setContentView(R.layout.listview);
QuestionsAndAnswersListAdapter adapter = new QuestionsAndAnswersListAdapter(data);
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
}
The adapter itself would look something like this:
public QuestionsAndAnswersListAdapter implements ListAdapter {
private QuestionAndAnswer[] data;
public QuestionsAndAnswersListAdapter(QuestionAndAnswer[] data) {
this.data = data;
}
public View getView(int position, View view, ViewGroup parent) {
if(view == null) {
//Only creates new view when recycling isn't possible
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.question_and_answer_list_item, null);
}
QuestionAndAnswer thisQA = data[position];
TextView questionView = (TextView) view.findViewById(R.id.text1);
questionView.setText(thisQA.question);
TextView answerView = (TextView) view.findViewById(R.id.answer);
answerView.setText(thisQA.answer);
return view;
}
// ...
}
getView is really the central method to get right. The rest of the methods you need to implement to live up to the ListAdapter interface are pretty straight-forward. Check the reference to see exactly what they are.

java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I know that there has been simialr questions but I can't make it work even though I look at those. The error message is:
java.lang.RuntimeException: Your content must have a ListView whose id
attribute is 'android.R.id.list'
. I have tried to change the id to list. In another. This what the code looks like:
public class committeeFragment extends SherlockListFragment {
private CommitteeAdapter adapter;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
adapter = new CommitteeAdapter(getActivity().getApplicationContext());
setListAdapter(adapter);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
return inflater.inflate(R.layout.fragment_committee, container, false);
}
public void
refreshList() {
adapter.updateDataSet();
adapter.notifyDataSetChanged();
}
}
It's using the following adapter:
public class CommitteeAdapter extends BaseAdapter {
private
ArrayList<StudentCommittee> committeeList;
private Context context;
public CommitteeAdapter(Context context) {
this.context = context;
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
public void updateDataSet() {
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
StudentCommittee committee = committeeList.get(position);
View v = vi.inflate(R.layout.list_item_committee, null);
TextView sectionName = (TextView) v.findViewById(R.id.committee_namn);
sectionName.setText(committee.getName());
return v;
}
#Override
public int getCount() {
return committeeList.size();
}
#Override
public StudentCommittee getItem(int position) {
return committeeList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
}
Here is the xml-file that specifies the list(fragment_committee):
<?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:tag="#string/tag_fragment_committee"
android:background="#color/white" >
<TextView
style="#style/AppsolutText.Headline"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Festerier" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#drawable/divider_sliding_menu_item"/>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
style="#style/AppsolutText.Normal"
android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Uppdatera för att se en lista över festerier och fadderier. Kräver internetanslutning."/>
</LinearLayout>
Here is the xml for the list 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="horizontal" >
<ImageView
android:id="#+id/committee_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" />
<TextView
android:id="#+id/committee_namn"
style="#style/AppsolutText.ListHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
I hope that you can figure out what's wrong. I have another listview that has the same id (list) in another xml-file within the project. I don't know if that's a problem. Please help me solve the problem.
The problem is here :
android:id="#+id/list"
you are adding a new id for your ListView but ListFragment needs a default Android ListView Id
change your ListView Id to :
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Change your ListView in XML to have the following id:
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
It's a requirement of using ListFragment/SherlockListFragment
http://developer.android.com/reference/android/app/ListFragment.html
ListFragment has a default layout that consists of a single list view. However, if you desire, you can customize the fragment layout by returning your own view hierarchy from onCreateView(LayoutInflater, ViewGroup, Bundle). To do this, your view hierarchy must contain a ListView object with the id "#android:id/list" (or list if it's in code)
You can try to clean your project. If any xml releted error have , you can find it. Then you can change your list id . Find the list id are exist into your gen folder R.java class.
I decided to stop using actionbarsherlock and use the support libraries instead to get action bar in Android 2.1 and above. After doing this, i got the "java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'". What i did to remedy this problem was
to read this http://developer.android.com/reference/android/app/ListFragment.html#q=fragment
then change my fragment layout file from
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"
tools:context=".ItemDetailFragment" />
to
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
tools:context=".ItemDetailFragment">
<ListView android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView android:id="#+id/item_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"/>
<TextView android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:text="No data"/>
... and voila, the RunTimeException with missing android.R.id.list was gone! Of course, i need to edit my new layout and fix it properly, but the key issue here was that i had overridden the fragment layout in its onCreateView method. ActionBarSherlock DID NOT have a problem with this, but with the Android support library, if u do this, you MUST have a ListView in your XML Layout, with the android:id="#id/android:list" as stated in the info linked to above.
Hope this helps (coming from a total newb in Android app dev)!

Android - can't combine views

I have one Activity in which I try to show some simple messages, and then a list of items. So as I understand, I need two views: one for the simple layout, and one for the list of items which will be handled by the adapter.
Here is my code:
ArrayAdapter<SolutionTopic> adapter;
ArrayList<SolutionTopic> problems = new ArrayList <SolutionTopic>( );
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Load your layout
setContentView(R.layout.solution);
SolutionTopic s = new SolutionTopic ();
s.setSolutionTopicName( "Hello" );
problems.add(s);
adapter = new ArrayAdapter<SolutionTopic>(this, R.layout.solution_topic_list,
R.id.label, problems);
TextView solution_title = (TextView) findViewById(R.id.solution_title);
TextView solution_description = (TextView) findViewById(R.id.solution_description);
setListAdapter (adapter);
}
and here is the solution.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/solution_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Label1"
/>
<TextView
android:id="#+id/solution_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Label2"
/>
</LinearLayout>
and here is the solution_topic_list.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
What I am not sure is how to get these two to render together. Ideally what I want to do is display the TextView messages first, and then the list of items.
Any idea how I can do that?
Thanks!
You shouldn't remove the ListView from solution.xml, in that ListView your SolutionTopics will be displayed.
To get the big picture, your interface would have three Views:
-TextView: #+id/solution_title
-TextView: #+id/solution_description
-ListView: #android:id/list
The ListView contains an undefined number of entries of solution_topic_list.xml.
PD: The third parameter of ArrayAdapter (R.id.label) should be the id of the TextView in solution_topic_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
You also should implement toString method in your SolutionTopic class, to get the desired String.

Categories

Resources