Use two different TextViews in Listview



I'm building an Android App and I decided to use a ListView. I want to use two textviews but ListView only adds the resultView:


Part of Activity.java



private ArrayAdapter<String> resultAdapter;
private ArrayAdapter<String> speechAdapter;

resultAdapter = new ArrayAdapter<String>(this, R.layout.result);
speechAdapter = new ArrayAdapter<String>(this, R.layout.speech);

String mostLikelyThingHeard = matches.get(0);
speechAdapter.add(mostLikelyThingHeard);
mainListView.setAdapter(speechAdapter);

String randomStr = "hello";
resultAdapter.add(randomStr);
mainListView.setAdapter(resultAdapter);


result.xml



<TextView xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:gravity="left" >

</TextView>


(speech.xml is the same, only the gravity is "right")


My ListView (Part of layout.xml)



<ListView
android:id="@+id/mainListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:headerDividersEnabled="false" />


So yeah, I hope you guys understand my problem,


I want to use the same ListView but mostLikelyThingHeard should be aligned to "right" and randomStr to "left"


No comments:

Post a Comment