I have a java class and two xml files which is basically just a side by side listView which takes in some values. I want to put a header or a text view above each list view ( i want them to stay side by side ) however every time I try to add a textView the whole project messes up and following online instructions isn't working to implement a header. I was wondering if anyone would be able to lend a hand
public class Leaderboard extends AppCompatActivity { private ListView UsernameList; private ListView ScoreList; LocalDatabase localDatabase; /** Called when the activity is first created */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_leaderboard); ArrayAdapter<String> listAdapter; ArrayAdapter<Integer> list2Adapter; //Find the ListView resources UsernameList = (ListView) findViewById(R.id.UsernameList); ScoreList = (ListView) findViewById(R.id.ScoreList); //Create and populate the list of usernames. //This is where the information from the Database would need to be entered. and the String[] removed String[] usernames = new String[]{"Andy", "Marie", "George"}; ArrayList<String> usernameList = new ArrayList<String>(); usernameList.addAll(Arrays.asList(usernames)); //Create and populate the list of scores //This is where the information from the Database would need to be entered. and the Integer[] removed Integer[] scores = new Integer[]{7, 4, 1}; ArrayList<Integer> scoreList = new ArrayList<Integer>(); scoreList.addAll(Arrays.asList(scores)); //adds the users details to the leaderboard localDatabase = new LocalDatabase(this); Contact contact = localDatabase.getLoggedInUser(); //Set a string to have the value of the users name. String s = contact.name; //Create Array Adapter using the username list listAdapter = new ArrayAdapter<String>(this, R.layout.activity_row, usernameList); //Add more users listAdapter.add(s); //Set the Array Adapter as the ListView's adapter UsernameList.setAdapter(listAdapter); //Create Array Adapter using the username list list2Adapter = new ArrayAdapter<Integer>(this, R.layout.activity_row, scoreList); //Add more users list2Adapter.add(0); //Set the Array Adapter as the ListView's adapter ScoreList.setAdapter(list2Adapter); } } Then the two xml files
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:background="@color/colorPrimaryDark" android:id="@+id/rowTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/white" android:textStyle="bold" android:padding="10dp" android:textSize="16sp"> </TextView> <?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:background="@color/colorPrimaryDark" android:layout_height="fill_parent" android:padding="20dp" android:orientation="horizontal" tools:context=".Leaderboard"> <ListView android:id="@+id/UsernameList" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_weight=".60" android:drawSelectorOnTop="false" android:headerDividersEnabled="false"> </ListView> <ListView android:id="@+id/ScoreList" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_weight=".40"> </ListView> </LinearLayout>
No comments:
Post a Comment