Searchable Dropdown spinner
hi ,, I have spinner full by sqlite database I want can search in it
how can i do that
I try used Autocomplete text but not worked well
this my spinner.aXml
<Spinner
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="#+id/SpinnerHotel"
android:paddingLeft="10dp"
android:background="#drawable/Spinner_Style"
android:spinnerMode="dropdown"
android:gravity="center"
android:visibility="visible"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp" />
and text_View.axml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:id="#+id/autoCompleteTextView1"
android:textColor="#68767A"
android:text="Select a Hotel .. "
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textSize="18dp" />
and this my Activity
async protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.GoShow_layout);
Agent = FindViewById<Spinner>(Resource.Id.SpinnerAgentt);
List<string> my_array = new List<string>();
my_array = await login.Get_Hotel();
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Resource.Layout.Text_View, my_array);
adapter.SetDropDownViewResource(Resource.Layout.Text_View);
Hotel.Adapter = adapter;
Hotel.ItemSelected += Hotel_ItemSelected;
}
private void Agent_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
var Spinner = sender as Spinner;
string Agentt = Spinner.GetItemAtPosition(e.Position).ToString();
Toast.MakeText(this, Agentt , ToastLength.Short).Show();
}
I think you have to combine Spinner with AutoCompleteTextView, like here Combine Spinner and AutoCompleteTextView
Related
I made this mobile app that can add table rows after pressing a button. Each row contains an Edittext, four dropdown menus (spinners), and a button that deletes a row. Each row is like a duplicate after I press the button "add". Now, my only problem is how to save that specific content into firebase's real-time database or could firestore. Do you guys have recommendations of how to do this, any resources, or is this question is broad? I can specify some things you're confused.
I can save an edit text that holds the title for the document, and it successfully works, except the table rows because it holds multiple data types. I just heard that firebase can only hold primitive datatypes.
This is the code that is relevant to the problem, so I won't have to paste all 357 lines of code.
private android.support.v7.widget.Toolbar maintoolbar, editToolBar;
private FirebaseAuth mAuth;
private FloatingActionButton fab;
private RelativeLayout layoutMain;
private RelativeLayout layoutButtons;
private RelativeLayout layoutContent;
private boolean isOpen = false;
private Button addnewRowButton, saveItButton;
private EditText titleofDoc;
private Context context = null;
private ProgressBar pb;
private DatabaseReference dr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
dr = FirebaseDatabase.getInstance().getReference().child("Notes").child(mAuth.getCurrentUser().getUid());
maintoolbar = findViewById(R.id.mainToolBar);
setSupportActionBar(maintoolbar);
getSupportActionBar().setTitle("Files");
layoutMain = findViewById(R.id.mainLays);
layoutButtons = findViewById(R.id.layoutButtons);
layoutContent = findViewById(R.id.layoutContent);
addnewRowButton = findViewById(R.id.AddRow);
saveItButton = findViewById(R.id.SaveThis);
titleofDoc = findViewById(R.id.TitleofDoc);
editToolBar = findViewById(R.id.main_edit_toolbar);
pb = findViewById(R.id.progressBar2);
saveItButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String title = titleofDoc.getText().toString().trim();
if (!TextUtils.isEmpty(title)) {
pb.setVisibility(View.VISIBLE);
createNew(title);
pb.setVisibility(View.INVISIBLE);
} else {
Snackbar.make(v, "Fill Empty Fields", Snackbar.LENGTH_SHORT).show();
pb.setVisibility(View.INVISIBLE);
}
}
});
addnewRowButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addNewRow();
}
});
fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
viewMenu();
}
});
}
This is the method that makes the table rows.
private void addNewRow() {
final TableLayout tl = findViewById(R.id.tbllays);
String[] teamRoles = {"Director", "Marketing", "Team", "All"};
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, teamRoles);
context = getApplicationContext();
//adds new row
final TableRow tbr = new TableRow(context);
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
tbr.setLayoutParams(layoutParams);
//add edittext to name the task
EditText editText = new EditText(context);
editText.setHint("Add Task");
tbr.addView(editText, 0);
//add spinner to assign teams
Spinner toDo = new Spinner(context);
toDo.setAdapter(adapter);
tbr.addView(toDo, 1);
//add spinner to assign teams
Spinner InProgress = new Spinner(context);
InProgress.setAdapter(adapter);
tbr.addView(InProgress, 2);
//add spinner to assign teams
Spinner Test = new Spinner(context);
Test.setAdapter(adapter);
tbr.addView(Test, 3);
//add spinner to assign teams
Spinner Done = new Spinner(context);
Done.setAdapter(adapter);
tbr.addView(Done, 4);
// Add a button in the second column
Button button = new Button(context);
button.setText("X");
tbr.addView(button, 5);
button.setBackgroundColor(Color.rgb(159, 168, 218));
// Get delete table row button.
Button deleteRowButton = (Button) button;
deleteRowButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
tbr.removeAllViews();
}
});
tl.addView(tbr);
}
This is the method that can only save the title instead of the content (the table rows in this case).
private void createNew(String title) {
if (mAuth.getCurrentUser() != null) {
final DatabaseReference newThingRef = dr.push();
final Map thingMap = new HashMap();
thingMap.put("title", title);
thingMap.put("timestamp", ServerValue.TIMESTAMP);
Thread mainThread = new Thread(new Runnable() {
#Override
public void run() {
newThingRef.setValue(thingMap).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Note added", Toast.LENGTH_SHORT).show();
Intent MainIntent = new Intent(MainActivity.this, MainActivity.class);
startActivity(MainIntent);
} else {
String error = task.getException().getMessage();
Toast.makeText(MainActivity.this, "ERROR: " + error, Toast.LENGTH_LONG).show();
}
}
});
}
});
mainThread.start();
} else {...}
}
This is the xml file (the part where the editor is held)
<RelativeLayout
android:id="#+id/layoutContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/mainToolBar"
>
<RelativeLayout
android:id="#+id/layoutButtons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:gravity="center"
android:visibility="gone">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainEditor">
<LinearLayout
android:id="#+id/LinLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="370dp">
<android.support.v7.widget.Toolbar
android:id="#+id/main_edit_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:indeterminate="true" />
<EditText
android:id="#+id/TitleofDoc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:ellipsize="end"
android:hint="#string/title"
android:importantForAutofill="no"
android:inputType=""
android:maxHeight="1dp"
android:maxLength="30"
android:maxLines="1"
android:padding="10dp"
tools:targetApi="o" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:alpha=".3"
android:background="#android:color/black" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<TableLayout
android:id="#+id/tbllays"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/AddRow"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_weight=".1"
android:background="#color/colorAccent"
android:text="#string/add_row"
android:textColor="#color/colorPrimaryDark" />
<Button
android:id="#+id/SaveThis"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_weight=".1"
android:background="#color/colorPrimaryDark"
android:text="#string/save" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="#string/task" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="#string/to_do" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_weight=".1"
android:text="#string/in_progress" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_weight=".1"
android:text="#string/testing" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_weight=".1"
android:text="#string/done" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="5"
android:layout_weight=".1"
android:text="#string/delete" />
</TableRow>
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
Ignore the user part, that is only if the user is signed in.
This is how it runs
You need to add an Listener at the end of each spinner and store in in the variable for example:
Spinner Done = new Spinner(context);
Done.setAdapter(adapter);
Done.setOnItemSelectedListner(this)
tbr.addView(Done, 4);
Then store this variable Done using DatabaseReference
You don't actually want to save the rows, you want to save the underlying content.
Instead of thinking of the on-screen rows as the content itself, think of them as just displaying your underlying content. This underlying content can be backed up, modified, whatever you want, whilst the representation of it on screen can be completely reconstructed at any time.
To convert your code, I'd suggest the following series of steps:
Create something like a Task class, that has all the fields you want (e.g. name, team).
Store a list of Tasks in your current Activity / Fragment class, e.g. private List<Task> myTasks.
Write a method displayTasks that removes all existing rows from your layout, then iterates through myTasks and draws them all to the screen.
Change addNewRow so that it adds a new Task to myTasks, then calls displayTasks.
You now have a list of Tasks, which can be written directly into Cloud Firestore, and be retrieved later.
I'm fully aware this answer isn't the simple "just do x" you're after, but it's the answer you actually need! All of the steps are very simple, and of course feel free to modify them for your use case.
Once you're comfortable with the concept of "what's on screen isn't my data, just a representation of it", you may want to look into LiveData and ViewModel. They're trickier, but with a lot of benefits (explained within the links).
I have two activity (DetailProduct and Wishlist) and i want to display data from DetailProduct to Wishlist, in here i using SharedPreferences for put data from DetailProduct to Wishlist.
This is my activity DetailProduct
wishlist.setOnClickListener(new View.OnClickListener() {
String imgpicaso = getIntent().getStringExtra("aaa");
String vardetailed = getIntent().getStringExtra("acb");
String thisname = getIntent().getStringExtra("name");
String text = getIntent().getStringExtra("abb");
#Override
public void onClick(View view) {
Intent tambah = new Intent(DetailProduct.this, Wishlist.class);
SharedPreferences sharedPreferences = DetailProduct.this.getSharedPreferences("baba", MODE_PRIVATE);
SharedPreferences.Editor shreditor = sharedPreferences.edit();
shreditor.putString("aaa", imgpicaso);
shreditor.putString("name", thisname);
shreditor.putString("abb", text);
shreditor.commit();
startActivity(tambah);
}
});
This is img DetailProduct
This is img Wishlist, please open this img
And this is file Wishlist.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wishlist);
setTitle("Your Wishlist");
ImageView resultgmb = (ImageView) findViewById(R.id.resultgmb);
TextView detailtok = (TextView) findViewById(R.id.detailtok);
TextView resulttext = (TextView) findViewById(R.id.resulttext);
Button bayarwish = (Button) findViewById(R.id.check);
Button hapus = (Button) findViewById(R.id.delete);
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("baba", MODE_PRIVATE);
String imgpicaso = sharedPreferences.getString("aaa", "");
Picasso.with(getBaseContext()).load(imgpicaso).into(resultgmb);
String detailtext = sharedPreferences.getString("name", "");
detailtok.setText(detailtext);
String text = sharedPreferences.getString("ccc", "");
resulttext.setText("$: " +text);
listproduct = (ListView) findViewById(R.id.listproduct);
ArrayList<String> arrayList = new ArrayList<>();
ArrayAdapter<String> arr = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
listproduct.setAdapter(arr);
arr.notifyDataSetChanged();
}
this is xml Wishlist
<SearchView
android:id="#+id/search"
android:background="#color/cardview_light_background"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</SearchView>
<LinearLayout
android:orientation="vertical"
android:id="#+id/relone"
android:layout_below="#id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/noimage"
android:id="#+id/resultgmb"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_alignParentRight="true"/>
<TextView
android:layout_marginTop="10dp"
android:text="setext"
android:textStyle="bold"
android:textColor="#000"
android:textSize="17dp"
android:id="#+id/detailtok"
android:layout_width="wrap_content"
android:layout_height="30dp" />
<TextView
android:text="setdescription"
android:layout_below="#id/detailtok"
android:textColor="#f00"
android:id="#+id/resulttext"
android:layout_width="wrap_content"
android:layout_height="30dp" />
<LinearLayout
android:layout_below="#id/resulttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHECK"/>
<Button
android:id="#+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DELETE"/>
</LinearLayout>
<ListView
android:id="#+id/listproduct"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</RelativeLayout>
</LinearLayout>
Please help me, thank you
As #sark9012 pointed out, you might want to use Intent Data rather than shared preferences for that purpose. Here is a tutorial on that.
Edit
Although I'd really advise against using Shared Preferences data for the purpose you're looking for, it seems you got the code correct for retrieving the data from the Shared Preferences, what you might be missing out on is populating the ListView. This is the code you sent us:
listproduct = (ListView) findViewById(R.id.listproduct);
ArrayList<String> arrayList = new ArrayList<>();
ArrayAdapter<String> arr = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
listproduct.setAdapter(arr);
arr.notifyDataSetChanged();
I don't really see you populating the adapter with the data retrieved, so you might want to have a look into that. Check this example from CodePath on how to setup the ListView with an ArrayAdapter.
Generate comma separated string and store that in shared preference
while storing to SP.
like string1 = a1+","a2+","a3;
while retrieving from SP.
like array[] = string1.split(",");
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, array);
I'm trying to populate sqlite records into a listview.
In my table, I'm splitting an address into columns e.g Street, Postcode, City & State.
I'm using SimpleCursorAdapter to load results into views like in the code below:
Here is my ListActivity.java
private DBManager dbManager;
private ListView listView;
private SimpleCursorAdapter adapter;
DbHelper myDb;
final String[] from = new String[] {
DbHelper.COL_NAME,
DbHelper.COL_STREET,
DbHelper.COL_POSTCODE,
DbHelper.COL_CITY,
DbHelper.COL_STATE };
final int[] to = new int[] { R.id.name, R.id.address };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_emp_list);
dbManager = new DBManager(this);
myDb = new DbHelper(this);
dbManager.open();
Cursor cursor = dbManager.fetch();
listView = (ListView) findViewById(R.id.list_view);
listView.setEmptyView(findViewById(R.id.empty));
adapter = new SimpleCursorAdapter(this, R.layout.activity_view_record, cursor, from, to, 0);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
Here is my view:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/name"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/id"
android:maxLines="1"
android:padding="3dp"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/nama"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/id"
android:ellipsize="end"
android:maxLines="2"
android:padding="3dp"
android:visibility="visible" />
</RelativeLayout>
My problem is, how to combine STREET, POSTCODE, CITY, STATE and put them into R.id.address?
Using the above method, i have to create a textview for each column, otherwise, it will error.
Make the following changes:
In your layout xml change
<TextView
android:id="#+id/address"
android:text="#string/format_address"
......
/>
In your strings.xm add the following:
<string name="format_address">%1$s, %2$s, %3$s, %4$s</string>
In your source code add the following:
Resources res = getResources();
String text = String.format(res.getString(R.string.format_address), STREET_VALUE, POSTCODE_VALUE, CITY_VALUE, STATE_VALUE);
NOTE STREET_VALUE, POSTCODE_VALUE, CITY_VALUE, STATE_VALUE replace with actual values or String ref.
I am trying to display DB records using a listView with SimpleCursorAdaptor. The app keeps crashing with the following error: Resource ID #0x7f0d0061 type #0x12 is not valid.
The crashing Java code is below
public class ViewActivity extends AppCompatActivity {
DatabaseHelper myDb;
ListView myList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
myDb = new DatabaseHelper(this);
myList = (ListView) findViewById(R.id.listViewLocations);
getListFromDb();
}
public void getListFromDb(){
Cursor res = myDb.ViewAll();
startManagingCursor(res);
//Map cursor from db to viewFields
String[] fromFieldNames = new String[]{DatabaseHelper.COL_2, DatabaseHelper.COL_3, DatabaseHelper.COL_4, DatabaseHelper.COL_5};
int[] toViewIDS = new int[]{R.id.viewName, R.id.viewAddress, R.id.viewPostcode, R.id.viewType};
//Create adaptor to map items from DB to UI
SimpleCursorAdapter myCursorAdaptor = new SimpleCursorAdapter(this, R.id.item_layout, res, fromFieldNames, toViewIDS, 0);
// Set adaptor for listView
myList.setAdapter(myCursorAdaptor);
}
The two XML files:
activity_view.xml
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listViewLocations"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
item_layout.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/viewName"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/viewAddress"
android:layout_below="#+id/viewName"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/viewPostcode"
android:layout_below="#+id/viewAddress"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/viewType"
android:layout_below="#+id/viewPostcode"
android:layout_alignParentStart="true" />
Why does it keep crashing and what can I do to fix it.
Cheers
The item_layout should be layout not id please change as below:
SimpleCursorAdapter myCursorAdaptor = new SimpleCursorAdapter(this, R.layout.item_layout, res, fromFieldNames, toViewIDS, 0);
Alright I'm stuck on populating a ListView in Android. This must be a tiring question for you guys but I can't find the problem. Basically it will produce placements in the ListView to hold texts, but it wont produce text. I checked my database class and it seems to be storing the data correctly, and I checked the syntax, but I cant find the problem.
Main activity that holds the list view
public class MainScreen extends ListActivity {
private TextView roommateId;
dbHelper db = new dbHelper(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
Log.i("Created", "main created");
ArrayList<HashMap<String, String>> roommates = db.getAllRoommates();
if(roommates.size()!=0){
ListView listView = getListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
roommateId = (TextView) view.findViewById(R.id.roommateId);
String roommateIdValue = roommateId.getText().toString();
Intent intent = new Intent(getApplication(), RoommateView.class);
intent.putExtra("roommateId", roommateIdValue);
startActivity(intent);
}
});
ListAdapter adapter = new SimpleAdapter(MainScreen.this, roommates, R.layout.contact_entry,
new String[] {"roommateId", "firstName", "lastName"},
new int[]{R.id.roommateId, R.id.lastName, R.id.firstName});
setListAdapter(adapter);
}
}
Database code that returns the array list
public ArrayList<HashMap<String,String>> getAllRoommates(){
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
String query = "SELECT * FROM " + DB_TABLE;
SQLiteDatabase data = this.getWritableDatabase();
Cursor cursor = data.rawQuery(query, null);
if(cursor.moveToFirst()){
do{
HashMap<String,String> roommateMap = new HashMap<String, String>();
roommateMap.put(ID, cursor.getString(0));
Log.d("Roommate ID", cursor.getString(0));
roommateMap.put(FIRST_NAME, cursor.getString(1));
Log.d("First Name", cursor.getString(1));
roommateMap.put(LAST_NAME, cursor.getString(2));
list.add(roommateMap);
}while(cursor.moveToNext());
}
return list;
}
contact entry xml
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/last_name"
android:id="#+id/lastName"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/first_name"
android:id="#+id/firstName"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/id"
android:id="#+id/roommateId"/>
</TableRow>
Main screen xml
<TableLayout 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"
tools:context=".MainActivity" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000" >
<TextView
android:id="#+id/contactsTitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:layout_weight="1"/>
<Button
android:id="#+id/button1"
android:background="#444444"
android:onClick="showAddRoommate"
android:text="#string/add_roommate"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
</TableRow>
</TableLayout>
Alright, I think I found the problem, it was that the String array in the simple adapter wasn't corresponding to the hash map key values, so when it was looking for key values that were not in the Hash Map. Change that and it populated. Putting the answer down incase anyone in the future sees this post.