Skip to content
Snippets Groups Projects
Commit 825e1f09 authored by darshanxyz's avatar darshanxyz
Browse files

Added ListView for displaying OD_List in TeacherActivity.java

parent c332c43f
No related branches found
No related tags found
No related merge requests found
package com.darshanbshah.odsystem;
/**
* Created by iamDarshan on 22/04/17.
*/
import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class CustomListAdapter extends ArrayAdapter {
static class DataHandler {
TextView tv;
}
List list = new ArrayList();
public CustomListAdapter(Context context, int resource) {
super(context, resource);
}
@Override
public void add(Object object) {
super.add(object);
list.add(object);
}
@Override
public int getCount() {
return this.list.size();
}
@Nullable
@Override
public Object getItem(int position) {
return this.list.get(position);
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
row = convertView;
DataHandler handler;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.list_item, parent, false);
handler = new DataHandler();
handler.tv = (TextView)row.findViewById(R.id.listText);
row.setTag(handler);
}
else {
handler = (DataHandler) row.getTag();
}
// Typeface one = Typeface.createFromAsset(parent.getContext().getAssets(), "fonts/BebasNeue Bold.ttf");
DataProvider provider = (DataProvider) this.getItem(position);
handler.tv.setText(provider.getDetector());
// handler.tv.setTypeface(one);
handler.tv.setTextSize(30);
return row;
}
}
package com.darshanbshah.odsystem;
/**
* Created by iamDarshan on 22/04/17.
*/
public class DataProvider {
private String detector;
public DataProvider(String detector) {
this.setDetector(detector);
}
public String getDetector() {
return detector;
}
public void setDetector(String detector) {
this.detector = detector;
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
......@@ -30,10 +31,13 @@ public class TeacherActivity extends AppCompatActivity {
DatabaseReference adv;
DatabaseReference student;
TextView t;
List<String> uid_list = new ArrayList<String>();
HashMap<String, String> uid_map = new HashMap<String, String>();
ListView listView;
CustomListAdapter adapter;
String adv_name;
@Override
......@@ -45,7 +49,7 @@ public class TeacherActivity extends AppCompatActivity {
od = root.child("OD");
adv = root.child("Advisors");
student = root.child("Student");
t = (TextView)findViewById(R.id.textView);
listView = (ListView)findViewById(R.id.listView);
adv.addChildEventListener(new ChildEventListener() {
@Override
......@@ -91,6 +95,14 @@ public class TeacherActivity extends AppCompatActivity {
uid_list.add(data.getKey());
}
}
adapter = new CustomListAdapter(getApplicationContext(), R.layout.list_item);
listView.setAdapter(adapter);
Log.e("UIDLIST_SIZE", String.valueOf(uid_list.size()));
for (String value: uid_list) {
DataProvider provider = new DataProvider(value);
adapter.add(provider);
}
}
@Override
......@@ -146,6 +158,7 @@ public class TeacherActivity extends AppCompatActivity {
}
});
}
public void signOut(View view) {
......
......@@ -4,28 +4,35 @@
android:id="@+id/activity_teacher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.darshanbshah.odsystem.TeacherActivity">
<Button
android:text="Logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="181dp"
android:id="@+id/button2"
android:onClick="signOut" />
android:onClick="signOut"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/button2"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="64dp"
android:id="@+id/textView" />
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="800dp"
android:id="@+id/listView">
</ListView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/listText"
android:layout_width="match_parent"
android:layout_height="100dp" />
</LinearLayout>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment