I created an adapter for my ListView that's displaying a data from my SQLite database, the problem is that in the ListView, I have 5 times the same line:
My adapter's code:
public class MyAdapter extends ArrayAdapter<Historique> {
private LayoutInflater mInflat;
private ArrayList<Historique> hist = new ArrayList<Historique>();
private int mVRessId;
public MyAdapter (Context context, int ressId, ArrayList<Historique> hists){
super(context,ressId,hists);
this.hist =hists;
mInflat = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mVRessId =ressId;
}
public View getView(int position, View convertedView, ViewGroup parents){
convertedView = mInflat.inflate(mVRessId,null);
Historique histor = hist.get(position);
if (histor != null){
TextView name = (TextView) convertedView.findViewById(R.id.hnom);
TextView quest = (TextView) convertedView.findViewById(R.id.hques);
TextView rep = (TextView) convertedView.findViewById(R.id.hrep);
TextView date = (TextView) convertedView.findViewById(R.id.hdate);
if (name != null){
name.setText(""+histor.getNom()+ ": "+histor.getLigne());
}
if (quest != null){
quest.setText(histor.getQuest());
}
if (rep != null){
rep.setText(histor.getRep());
}
if (date != null){
date.setText(histor.getDate().toString());
}
}
return convertedView;
}
}
The ListView must display the list, and here's the code:
final MyAdapter adapter = new MyAdapter (this, R.layout.adapter_view_layout,histList);
mCsr = openhelper.getTableHistoAsCursor();
int rows = mCsr.getCount();
if (rows == 0 ){
Toast.makeText(Historian.this, "Pas d'historique disponible", Toast.LENGTH_SHORT).show();
} else {
while (mCsr.moveToNext()){
histo = new Historique(mCsr.getString(0).toString(),mCsr.getString(1).toString(), mCsr.getString(2).toString(),mCsr.getString(3).toString(),mCsr.getString(4).toString());
histList.add(histo);
}
}
mListView .setAdapter(adapter);
The getTableHisto is a function that returns a cursor from my SQLite Modelhelper:
public Cursor getTableHistoAsCursor() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor data = db.rawQuery(" SELECT Q." + KEY_QUESTION + " ,L." + KEY_LIGNE + " , U." + KEY_NOM + " , A." + KEY_DATE + " , A. " + KEY_REPONSE + " from "+ TABLE_LIGNE + " L, " + TABLE_QUESTION + " Q, " + TABLE_USER + " U, " + TABLE_ANSWER + " A WHERE Q." + KEY_ID_QUESTION + " = A." + KEY_ID_QUESTION + " AND A." + KEY_MATRICULE + " = U." + KEY_MATRICULE, null);
return data;
}
In the first time, I thought that in the insert I was doing something wrong and it goes 5 times in the database, so I've created an activity to try to get the number of inserts with a Select count();
And I saw that the result that I'm getting is the true result, I don't insert 5 times the same line, but the adapter is displaying it 5 times in 5 lines.
If you have any idea that can help me, I would be thankful.
thanks.
//Initialize my adapter after populating the list
histList.add(histo);
Adapter is only initialized after populating values in the Array List
not with null values.
final MyAdapter adapter = new MyAdapter (this, R.layout.adapter_view_layout,histList);
mListView .setAdapter(adapter);
I got it, the problem is solved, in case someone has the same problem, the loop wasn't good so I changed
else {
while (mCsr.moveToNext()){
by
else {
if (mCsr != null){
mCsr.moveToFirst();
Related
I made SQL database and populated it with values. In TextView I need to show multiply result of specific rows.
I made SQL statement and I hope that is correct.
public List<Food> multiplyFat(){
String totalFat = "SELECT " +FoodEntry.COLUMN_FAT_TOTAL + " FROM " + FoodEntry.TABLE_NAME + " WHERE ( "
+FoodEntry.COLUMN_FAT_TOTAL + " * " + FoodEntry.COLUMN_GRAM + " ) > 0";
SQLiteDatabase db = this.getWritableDatabase();
List<Food> storeTotalFat = new ArrayList<>();
Cursor cursor = db.rawQuery(totalFat, null);
if (cursor.moveToFirst()){
do {
double fat = Double.parseDouble(cursor.getString(0));
storeTotalFat.add(new Food(fat));
} while (cursor.moveToNext());
}
cursor.close();
return storeTotalFat;
}
To be more clear I need to multiply values from row COLUMN_FAT_TOTAL with row COLUMN_GRAM and display result into the TextView. Or should I put these SQL statement:
String totalFat = "SELECT " +FoodEntry.COLUMN_FAT_TOTAL + " * " +FoodEntry.COLUMN_GRAM + " FROM " +FoodEntry.TABLE_NAME;
That is simplier way but I am not sure that it is correct way.
Anyhow I need to display this multiplyFat() function (result) into TextView. Any help or advice would be really helpfull.
public List multiplyFat(){
String totalFat = "SELECT " +FoodEntry.COLUMN_FAT_TOTAL + " FROM " + FoodEntry.TABLE_NAME + " WHERE ( "
+FoodEntry.COLUMN_FAT_TOTAL + " * " + FoodEntry.COLUMN_GRAM + " ) > 0";
The above works perfectly in MySQL, I just tried it.
SQLiteDatabase db = this.getWritableDatabase(); --> db = this.getReadableDatabase();
Since you are not changing anything in the SQLite database you want a '.getReadableDatbase();' not '.getWritableDatabase();'
List<Food> storeTotalFat = new ArrayList<>();
Cursor cursor = db.rawQuery(totalFat, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
do {
double fat = Double.parseDouble(cursor.getString(0));
storeTotalFat.add(new Food(fat));
} cursor.moveToNext();
}
cursor.close();
return storeTotalFat;
}
See how I first moved to the first index, then I ask it to continue in a while loop until it has reached the final element in the SQL results. Your way was not actually incrementing the cursor, it would have only been able to add the first result to the storeTotalFat ArrayList.
-------- part 2 ---------
Now let's pretend we are back in the activity, woo!
Let's say there is a class variable reference to the database helper and add a new ArrayList to house the results from the query result we just gained.
DBHelper myDBhelper = DBHelper.getInstance(MainActivity.this)
ArrayList<String> sqlResultArray = new ArrayList<>();
If you want a Recyclerview you make a separate RviewAdapter class, in your case FoodFatRecyclerViewAdapter and add the following
RecyclerView rv = (RecyclerView) findViewById(R.id.foodFatRecView);
LinearLayoutManager llm = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(llm);
FoodFatRecyclerViewAdapter foodFatAdapter = new FoodFatRecyclerViewAdapter(MainActivity.this, sqlResultArray);
rv.setAdapter(foodFatAdapter);
Now as for the adding of the result to the textview create a new class called FoodFatRecyclerViewAdapter
public class FoodFatRecyclerViewAdapter extends RecyclerView.Adapter<FoodFatViewHolder> {
ArrayList<String> mFoodFatItems;
Context mContext;
public FoodFatRecyclerViewAdapter(Context context, ArrayList<String> array) {
mContext = context;
mFoodFatItems = array;
}
#Override
public FoodFatViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.this_xml_layout_will_describe_the_arrangement_of_the_indi_item_in_the_list_not_the_master_view, parent, false);
FoodFatViewHolder recyclerView = new FoodFatViewHolder(view);
return recyclerView;
}
#Override
public void onBindViewHolder(FoodFatViewHolder holder, final int position) {
holder.mFatTotalTextView.setText(mFoodFatItems.get(position));
}
#Override
public int getItemCount() {
return mFoodFatItems.size();
}
}
Now the final piece to the puzzle, the View Holder so create a class called FoodFatViewHolder
public class FoodFatViewHolder extends RecyclerView.ViewHolder{
TextView mFatTotalTextView;
public FoodFatViewHolder(View itemView) {
super(itemView);
mFatTotalTextView = (TextView) itemView.findViewById(R.id.the_textview_id_within_the_individ_item_in_rv_xml_layout);
}
}
Voila! It should work
You need to show the multiplication total then you shouldn't do a select on COLUMN_FAT_TOTAL. Instead you should do the computation in your select query and store that computation in an alias. You can then use that alias as a result.
Modify your query as below
String totalFat = "SELECT " +FoodEntry.COLUMN_FAT_TOTAL + " * " + FoodEntry.COLUMN_GRAM + "AS Result FROM " + FoodEntry.TABLE_NAME";
You are on the right track. Do the math in the database if it is easy and straight forward, which this example is.
Might I suggest the following (similar to kapsym answer) for your sql statement:
String totalFat = "SELECT " + FoodEntry.COLUMN_FAT_TOTAL + ", " + FoodEntry.COLUMN_GRAM + "," FoodEntry.COLUMN_FAT_TOTAL + " * " + FoodEntry.COLUMN_GRAM + "AS TotalFat FROM " + FoodEntry.TABLE_NAME + " WHERE ( " + FoodEntry.COLUMN_FAT_TOTAL + " * " + FoodEntry.COLUMN_GRAM + " ) > 0";
You should study the basics of MySQL : https://www.tutorialspoint.com/mysql/mysql-select-query.htm
After the SELECT, you add column names that you want to retrieve and not expressions.
For your case, Use this Query to get all fat_total & gram entries :
String totalFat = "SELECT " + FoodEntry.COLUMN_FAT_TOTAL + "," + FoodEntry.COLUMN_GRAM + " FROM " + FoodEntry.TABLE_NAME;
Then you retrieve fatTotal * gram for each cursor, multiply it and feed it into your storeTotalFat array based on (!= 0) condition.
Cursor cursor = db.rawQuery(totalFat, null);
if (cursor.moveToFirst()){
do {
double fat = Double.parseDouble(cursor.getString(0));
double gram= Double.parseDouble(cursor.getString(1));
if (fat * gram != 0)
storeTotalFat.add(new Food(fat * gram));
} while (cursor.moveToNext());
}
I have just started coding an Android App using Android Studio 2.1 and my app was sort of an offline messaging - this is using SQLite Database (basically compose of two tables message and contact).
I am now in my last activity where I need to populate a list of message exchange from the contacts created. I was able to list them but without aesthetics. I would like to set different setBackgroundResource whenever the type is either a LEFT or RIGHT but was struggling to apply it.
Below is my code:
MessageRepo - the SQLite DBhelper:
public ArrayList<HashMap<String, String>> getMessageListById(int fromid, int toid) {
SQLiteDatabase db = helper.getWritableDatabase();
String toquery = "SELECT " + MessageModel.messageId +
", " + MessageModel.fromId +
", " + MessageModel.toId +
", " + MessageModel.messageContent +
", 'RIGHT' AS type FROM " + MessageModel.tableMessage +
" WHERE " + MessageModel.toId +
" = ? AND " + MessageModel.fromId +
" = ? ";
String fromquery = "SELECT " + MessageModel.messageId +
", " + MessageModel.fromId +
", " + MessageModel.toId +
", " + MessageModel.messageContent +
", 'LEFT' AS type FROM " + MessageModel.tableMessage +
" WHERE " + MessageModel.fromId +
" = ? AND " + MessageModel.toId +
" = ? ";
String query = toquery +
" UNION " + fromquery +
" ORDER BY " + MessageModel.messageId;
ArrayList<HashMap<String, String>> messageList = new ArrayList<HashMap<String, String>>();
Cursor cursor = db.rawQuery(query, new String[]{String.valueOf(fromid), String.valueOf(toid), String.valueOf(fromid), String.valueOf(toid)});
if (cursor.moveToFirst()) {
do {
HashMap<String, String> messages = new HashMap<String, String>();
messages.put("messageId", cursor.getString(0));
messages.put("messageFromId", cursor.getString(1));
messages.put("messageToId", cursor.getString(2));
messages.put("messageContent", cursor.getString(3));
messages.put("type", cursor.getString(4));
messageList.add(messages);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return messageList;
}
Message Activity - this will display in a ListView but not working as I was intending it to display:
ArrayList<HashMap<String, String>> messageList = messagehandler.getMessageListById(_fromid, _toid);
if (messageList.size() != 0) {
ListView listView = getListView();
if(messageList.contains("RIGHT")) {
listView.setBackgroundResource(R.drawable.right);
} else {
listView.setBackgroundResource(R.drawable.left);
}
ListAdapter adapter = new SimpleAdapter(MessageDetailActivity.this, messageList, R.layout.message, new String[]{"messageFromId", "messageToId", "messageContent"}, new int[]{R.id.FromId, R.id.ToId, R.id.message});
setListAdapter(adapter);
}
I've checked a lot of posts and I can't seem to make it work for me:
The constructor ArrayAdapter>>(Context, int, ArrayList>) is undefined
Android Alternate row Colors in ListView
Thanks a lot in advance!
After researching a bit more. I finally found the answer by opting to use List and a setter/getter class:
public class MessagesAdapter extends ArrayAdapter<ContactsAndMessages> {
public MessagesAdapter(Context context, List<ContactsAndMessages> contacts) {
super(context, 0, contacts);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ContactsAndMessages contact = getItem(position);
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica.ttf");
if(convertView == null) {
if (contact.type.equalsIgnoreCase("me")) {....
I'm new to android, and I don't know why I am getting CursorIndexOutOfBoundsException: Index 0 requested with a size of 0. I'm trying to display it on another class using listview. Here are my codes:
public void onItemClick(AdapterView<?> arg0, View view, int position,
long id) {
// TODO Auto-generated method stub
position = position + 1;
Cursor a = MainActivity.sqldb
.rawQuery("Select name from " + MainActivity.tblpb
+ " where _pid = " + position + ";", null);
String aa = a.getString(a.getColumnIndex("name"));
Cursor b = MainActivity.sqldb
.rawQuery("Select phone from " + MainActivity.tblpb
+ " where _pid = " + position + ";", null);
String bb = b.getString(b.getColumnIndex("phone"));
Intent next = new Intent (this, ThirdActivity.class);
startActivity(next);
}
I know that there's something really wrong here. And I wonder what it is.
Create Table:
sqldb = this.openOrCreateDatabase(dbpb, MODE_PRIVATE, null);
sqldb.execSQL("CREATE TABLE IF NOT EXISTS "
+ tblpb
+ " (_pid INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, phone INTEGER);");
Insert Table:
sqldb.execSQL("Insert into " + tblpb
+ " (name, phone) Values ('" + x + "' , '"
+ y + "' );");
Try doing this:
public void onItemClick(AdapterView<?> arg0, View view, int position,
long id) {
// TODO Auto-generated method stub
String aa = null;
String bb = null;
// do not alter the position, DB starts the same position as ItemClick for
// adapter view
// position = position + 1;
Cursor a = MainActivity.sqldb
.rawQuery("Select name from " + MainActivity.tblpb
+ " where _pid = " + position + ";", null);
if(a != null){
// Force cursor to position 0
if(a.moveToFirst()){
// make sure the column actually exists
aa = a.getString(a.getColumnIndexOrThrow("name"));
Log.d("Cursor A - Name", "name column val: "+ aa);
}else{
Log.d("Cursor A", "cursor A failed to move to first");
}
}else{
Log.d("Cursor A null", "cannot access cursor A");
}
Cursor b = MainActivity.sqldb.rawQuery("Select phone from " + MainActivity.tblpb + " where _pid = " + position + ";", null);
if(b != null){
// Force cursor to position 0
if(b.moveToFirst()){
// make sure the column actually exists
bb = b.getString(b.getColumnIndexOrThrow("phone"));
Log.d("Cursor B - Phone", "phone column val: "+ bb);
}else{
Log.d("Cursor B", "cursor B failed to move to first");
}
}else{
Log.d("Cursor B null", "cannot access cursor B");
}
Intent next = new Intent (this, ThirdActivity.class);
next.putExtra("NAME", aa);
next.putExtra("PHONE", bb);
startActivity(next);
}
Then in your second Activity do:
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.content_file);
Bundle extras = getIntent().getExtras();
if(extras != null){
String aa = extras.getString("NAME");
String bb = extras.getString("PHONE");
// Since you cannot tell if these are null check them
if(aa != null){
// ... Use on your TextView
}
// Since you cannot tell if these are null check them
if(bb != null){
// ... Use on your TextView
}
}
}
The error indicates that you are trying to access the first element (index 0) of an empty list (size 0) meaning your queries are returning no results. Make sure your queries are correct.
EDIT:
It's also a good idea to call cursor.moveToFirst() and check its result before doing any operations on the data from a query.
http://developer.android.com/reference/android/database/Cursor.html#moveToFirst%28%29
I'm obviously missing something in making this custom adapter. Basically, I've got code that grabs JSON from the site, then breaks it down into a ArrayList. I can do a .toString() and spit it all out onto a listview just fine, but everything I find on the net for creating a custom adapter creates the list inside of it. Is there a way to just supply your pre-created list? I've yet to make any headway on getting the custom one to work...but, as I said I can get the string to work just fine, so I'll include that code.
Here's my classes:
public class JSONEvents {
String eid;
String bid;
private String bname;
private String valid;
#Override
public String toString() {
return "Events [eid=" + eid + ", bid=" + bid + ", bname=" + bname
+ ", start=" + start + ", end=" + end + ", points=" + points
+ ", title=" + title + ", description=" + description
+ ", cat=" + cat + ", type=" + type + ", subtype=" + subtype
+ ", valid=" + valid + "]";
}
public String getEventInfo(String field){
if("eid".equals(field)){return eid;}
else if("bid".equals(field)){return bid;}
else if("bname".equals(field)){return bname;}
else if("valid".equals(field)){return valid;}
return "none";
}
}
public class JSONAdventures {
private String aid;
private String bid;
private String start;
private String valid;
#Override
public String toString() {
return "Adventures [aid=" + aid + ", bid=" + bid + ", start=" + start
+ ", end=" + end + ", points=" + points + ", title=" + title
+ ", description=" + description + ", cat=" + cat + ", type="
+ type + ", subtype=" + subtype + ", steps_comp=" + steps_comp
+ ", total_steps=" + total_steps + ", valid=" + valid + "]";
}
public String getEventInfo(String field){
if("aid".equals(field)){return aid;}
else if("bid".equals(field)){return bid;}
else if("start".equals(field)){return start;}
else if("valid".equals(field)){return valid;}
return "none";
}
}
public class JSONEandA {
private ArrayList<JSONEvents> events;
private ArrayList<JSONAdventures> adventures;
#Override
public String toString() {
return "ResponseHolder [events=" + events + ", adventures="
+ adventures + "]";
}
public ArrayList<JSONEvents> getJSONEvents() {
return events;
}
public ArrayList<JSONAdventures> getJSONAdventures() {
return adventures;
}
}
For the code in m activity:
List<JSONEvents> eventlist = new ArrayList<JSONEvents>();
try {
Gson googleJson = new Gson();
JSONEandA rh = googleJson.fromJson(example,
JSONEandA.class);
for (JSONEvents e : rh.getJSONEvents()) {
eventlist.add(e);
//eventlist.addAll(e);
// System.out.println(e.toString());
System.out.println(e.getEventInfo("eid"));
System.out.println(e.toString());
}
final ListView listview = (ListView) findViewById(R.id.eventlistview);
String[] values = new String[eventlist.size()];
eventlist.toArray(values);
// String[] values = new String[] {e.toString()};
final ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < values.length; ++i) {
list.add(values[i]);
}
final StableArrayAdapter adapter = new StableArrayAdapter(
Events.this,
android.R.layout.simple_list_item_1, list);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent,
final View view, int position, long id) {
final String item = (String) parent
.getItemAtPosition(position);
list.remove(item);
adapter.notifyDataSetChanged();
Toast.makeText(getApplicationContext(),
"Item Removed", Toast.LENGTH_LONG).show();
});
I've also pieced together an attempt at an adapter from various tutorials and such, but can't figure out how to tie it all together:
class EventAdapter extends ArrayAdapter<JSONEvents> {
private ArrayList<JSONEvents> items;
public EventAdapter(Context context, int textViewResourceId,
ArrayList<JSONEvents> items) {
super(context, textViewResourceId, items);
this.items = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_events, null);
}
JSONEvents q = items.get(position);
if (q != null) {
TextView nameText = (TextView) v.findViewById(R.id.firstline);
TextView priceText = (TextView) v.findViewById(R.id.secondLine);
if (nameText != null) {
nameText.setText(q.getEventInfo("eid"));
}
if (priceText != null) {
priceText.setText(q.getEventInfo("bid"));
}
}
return v;
}
}
I would appreciate any help, thanks!
Did you put tha data into your adapter?
adapter.addAll(String[] data);
Or you could do it while creating adapter:
EventAdapter adapter = new EventAdapter(this, R.id.some_id, eventlist);
I want get info Object in row item ListView ..listview load info in database..
add Income
public void addIncome(OIncome income) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(TABLE_INCOME_COLUMN_NAME, income.get_name());
values.put(TABLE_INCOME_COLUMN_CATEGORY, income.get_category() + 1);
values.put(TABLE_INCOME_COLUMN_AMOUNT, income.get_amount());
values.put(TABLE_INCOME_COLUMN_DATE, income.get_date());
values.put(TABLE_INCOME_COLUMN_TIME, income.get_time());
values.put(TABLE_INCOME_COLUMN_NOTE, income.get_note());
db.insert(TABLE_INCOME, null, values);
db.close();
}
Get Income
public List<OIncome> getIncome() {
List<OIncome> list = new ArrayList<OIncome>();
String selectIncome = "SELECT * FROM " + TABLE_INCOME + " INNER JOIN "
+ TABLE_CATEGORY + " ON " + TABLE_CATEGORY + "."
+ TABLE_CATEGORY_COLUMN_ID + "=" + TABLE_INCOME + "."
+ TABLE_INCOME_COLUMN_CATEGORY + " WHERE " + TABLE_INCOME + "."
+ TABLE_INCOME_COLUMN_DATE + "=" + "'" + GET_DATE + "'"
+ " ORDER BY " + TABLE_INCOME + "." + TABLE_INCOME_COLUMN_DATE
+ " DESC";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectIncome, null);
if (cursor.moveToFirst()) {
do {
OIncome income = new OIncome();
income.set_amount(cursor.getFloat(3));
income.set_category(cursor.getInt(8));
income.set_name(cursor.getString(1));
income.set_date(cursor.getString(4));
income.set_time(cursor.getString(5));
list.add(income);
} while (cursor.moveToNext());
}
return list;
}
in class ListIncomeAdapter
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(layout, null);
}
OIncome income = list.get(position);
TextView tvnameincome = (TextView) convertView
.findViewById(R.id.tvnameincome);
TextView tvdateincome = (TextView) convertView
.findViewById(R.id.tvdateincome);
TextView tvtimeincome = (TextView) convertView
.findViewById(R.id.tvtimeincome);
TextView tvamountincome = (TextView) convertView
.findViewById(R.id.tvamountincome);
ImageView imglistincome = (ImageView) convertView
.findViewById(R.id.imglistincome);
Other other = new Other();
// OCatergory catergory = data.get(position);
tvnameincome.setText(income.get_name());
tvdateincome.setText(other.convertDateYear(income.get_date()));
tvtimeincome.setText(income.get_time());
tvamountincome.setText(income.get_amount() + "");
imglistincome.setImageResource(income.get_category());
return convertView;
}
How can I get the information of that item..
please give me a few lines of
get information on that item
You have to extract it from the parent, like below. I'm not 100% sure on the syntax though, because I don't have my Android workspace here.
OIncome income = (OIncome) ((ListView) parent).getItemAtPosition(position);
This replaces your line of code, which throws the Cast Exception:
OIncome income = list.get(position);