-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdapter.java
41 lines (32 loc) · 1.16 KB
/
Adapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class Adapter extends AppCompatActivity {
ListView textlist;
ArrayList <String>listItem;
ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item);
DBHandler dbHandler = new DBHandler(this);
listItem = new ArrayList<>();
textlist = findViewById(R.id.list_text);
Cursor cursor = dbHandler.alldata();
if (cursor.getCount() == 0){
Toast.makeText(getApplicationContext(), "No data", Toast.LENGTH_LONG).show();
}
else{
while (cursor.moveToNext()){
listItem.add(cursor.getString(1));
}
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2,listItem);
textlist.setAdapter(adapter);
}
}
}