I want to display contacts in list view and add actions on all contacts , like on click on a particular contact it should display the phone number , mail id and delete of the particular contact...
import android.app.ListActivity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class CPDemo1 extends ListActivity {
#SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String str[]= {"datta","vivek","Nagesh sir","shiv"};
String name;
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
int nameIdx = cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
if (cursor.moveToFirst())
do {
int x = 0;
name = cursor.getString(nameIdx);
str[x]= name;
x++;
ArrayAdapter arr = new ArrayAdapter(this, android.R.layout.simple_list_item_1,str);
setListAdapter(arr);
} while(cursor.moveToNext());
}
The problem in your current code is create new adapter for every loop. Just move ArrayAdapter arr = new ArrayAdapter(this, android.R.layout.simple_list_item_1,str);
out of do while loop. And another issue, You work too much on UIThread (loop through cursor )so user will see a black screen or ANR if your numbers of contact is huge. Learn to use AsyncQueryHandler and CursorAdapter, it's all in my link and nikki's link
And why don't you have a look at default Contacts app in Android source code:
Below is my custom Contacts App.
https://github.com/android/platform_packages_apps_contacts
Just have a look at below link and try using this code for displaying contacts saved in android phone book into your application.
http://developer.android.com/resources/samples/ContactManager/index.html
Here is a little change to the code posted by you, it will solve your problem.
if (cursor.moveToFirst())
{
int x = 0;
do {
name = cursor.getString(nameIdx);
Log.d("CONTENT",name);
str[x]= name;
x++;
} while(cursor.moveToNext());
ArrayAdapter<String> arr = new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_1,str);
setListAdapter(arr);
Related
On running the application, it displays an error as"Unable to start activity.. ComponenInfo" with length =64 and index=64 and the app crashes. Is there any solution to it?
package com.mayank.app.quizoclash;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class game extends AppCompatActivity implements View.OnClickListener {
private TextView ques, score, quesno,time;
Button opt1, opt2, opt3, opt4,image;
String phone,phone1,name,college,regno;
int count1=0;
int count=0;
int i=0,j=0,k=1;
private String[] question={"What was Slade Wilson's alter ego?","What is the name of this episode?","Which Dire-wolf belonged to Robb?","What is the color of the couch in the coffee shop in F.R.I.E.N.D.S?","How does Sherlock first have his coffee?","Who told the Flash to wear a mask or suit?","What is Kristy Stapleton's rabbit called?",
"What was the name of Monica's Boyfriend who was an alcoholic","What are Daenerys Dragons called","Phoebe changes her name to?","In How I Met Your mother, What is Robin's occupation?","How many friends does Sheldon have on MySpace?(BBT)","Rachel gets a tattoo. What is it?","Which man did this woman go on a date with?",
"In the series \"Arrow,\" who is character Oliver Queen's best friend?","What two characters featured prominently in the TV series did not appeear in the comics version?(The Walking Dead)","This police inspector regularly calls on Holmes to help solve difficult cases.","In what drug (now illegal) was Holmes known to imbibe, from time to time.",
"Who does Sheldon believe has an \"unresolved Oedipus complex\"?(BBT)","What card did Joey think was stolen by the guy who robbed the apartment?","What is \"Arrow\" character John Diggle's profession?","What is the setting for Holmes and Moriarty's final, fatal encounter?","What instrument does Leonard play?(BBT)","How many blocks was Rachel's childhood dog LaPooh dragged?",
"What was T-Dog's real name?(The Walking Dead)","What is Daredevil's alter ego?","What phrase did the Arrow use when he questioned someone on his father's list?","In Season 2, who is the manager of Central Perk?(Friends)","Where did Amy go to college?(BBT)","How did Holmes describe himself professionally?","Unlike many superheroes, Daredevil is deeply religious. What is his faith?",
"Which girl did this guy date?","What was the pendant on the necklace Andrea planned to give Amy for her birthday?","What catastrophic event was the Undertaking, that destroyed a large part of The Glades?","What was the London address of the famous sleuth and his faithful companion, Dr. Watson?","Halfway through the movie, Colin Farrell is introduced as Kingpin's assassin of choice. What is the name of his character, who \"can turn anything into a weapon\"?","In \"The One With the Lottery,\" what is the power ball number?","What does CDC Dr. Edwin Jenner liken the zombie virus to?",
"Barry served as best man at whose wedding?","Who accompanies Sheldon and Amy on their first dinner date?(BBT)","Who turned out to be Thea's biological father, who saved her from one of Slade's superhuman soldiers?","Barry's longtime girlfriend was Iris West. What century is she from?","'Suits' is set in a law office. Can you name it?","After they've fallen in love, Elektra gets Daredevil's alter ego a ticket to a ball. He goes, accompanied by his partner at work. What does Elektra wear?","Phoebe's brother let her name one of his triplets. What did she name her?",
"In Sherlock, Benedict Cumberbatch is Sherlock Holmes but who plays Doctor Watson?","How many dragons did Daenerys Targaryen originally have in The Game of Thrones?","What does VALAR MORGHULIS signify?","What was the name of the witch burned alive by Danerys on the funeral pyre of Khal Dargo?","In Breaking Badwhat was Walter White baby daughter's first name?","Sybil Buchanan is a character from which of these US TV series?","Margaret Schroeder is a character from which TV series","What is Monica's last name in tv series Friends?","What name is given to the seat of House Baratheon? ","Heisenberg?","An FX original, each season has a new story but some of same actors?","News program featuring real life cases?","Travel Chanel-Zak,Aaron,Billy,Jay and spirits?","Spin off from The Walking Dead?"
,"The Braverman's were the family on what drama series?","The Ghost Adventures Crew are originally from what city?","Sunday night AMC,- Rick, Daryl, Glen?","General Hospital takes place in what city?","Damon,Stefon,Elena,Bonnie and Caroline"};
MyCountDownTimer countDownTimer = new MyCountDownTimer(12000 /* 12 Sec */,
1000);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toast.makeText(this," fgd",Toast.LENGTH_SHORT).show();
Intent i = getIntent();
phone = i.getStringExtra("phone");
phone1 = i.getStringExtra("phone1");
name = i.getStringExtra("name");
college = i.getStringExtra("college");
regno = i.getStringExtra("regno");
countDownTimer.start();
toolbar.setTitle("TV Series");
setSupportActionBar(toolbar);
opt1=(Button)findViewById(R.id.opt1);
count1=0;
opt2=(Button)findViewById(R.id.opt2);
opt3=(Button)findViewById(R.id.opt3);
opt4=(Button)findViewById(R.id.opt4);
time = (TextView) findViewById(R.id.time);
opt1.setOnClickListener(this);
opt2.setOnClickListener(this);
opt3.setOnClickListener(this);
opt4.setOnClickListener(this);
ques=(TextView)findViewById(R.id.ques);
quesno=(TextView)findViewById(R.id.quesno);
Toast.makeText(this," fgd",Toast.LENGTH_SHORT).show();
shuffleArray1(question, (Gamesupport2.option1), (Gamesupport2.option2), (Gamesupport2.option3), (Gamesupport2.option4));
ques.setText(question[0]);
opt1.setText(Gamesupport.option1[0]);
opt2.setText(Gamesupport.option2[0]);
opt3.setText(Gamesupport.option3[0]);
opt4.setText(Gamesupport.option4[0]);
}
#Override
public void onClick(View v) {
if(v==opt2)
{
++count;
next();
}
else
next();
}
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
static void shuffleArray1(String[] q, String[] option1, String[] option2, String[] option3, String[] option4) {
// If running on Java 6 or older, use `new Random()` on RHS here
Random rnd = ThreadLocalRandom.current();
for (int i = q.length; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
String a = q[index];
q[index] = q[i];
q[i] = a;
String e = option1[index];
option1[index] = option1[i];
option1[i] = e;
String b = option2[index];
option2[index] = option2[i];
option2[i] = b;
String c = option3[index];
option3[index] = option3[i];
option3[i] = c;
String d = option4[index];
option4[index] = option4[i];
option4[i] = d;
}
}
private void next() {
for(i=i+1;i<=question.length;i++,j++)
{
count1++;
countDownTimer.start();
if(count1==64)
{
countDownTimer.cancel();
String str=""+count;
Intent i = new Intent(this, Score.class);
i.putExtra("phone", phone);
i.putExtra("score", str);
i.putExtra("name",name);
i.putExtra("phone1",phone1);
i.putExtra("college",college);
i.putExtra("regno", regno);
startActivity(i);
break;
}
ques.setText(question[i]);
opt1.setText(Gamesupport.option1[i]);
opt2.setText(Gamesupport.option2[i]);
opt3.setText(Gamesupport.option3[i]);
opt4.setText(Gamesupport.option4[i]);
if(count1==1||count1==2 || count1==3 || count1==4|| count1==5||count1==6||count1==7||count1==8||count1==9||count1==10||count1==11||count1==12||count1==13||count1==14||count1==15||count1==16 || count1==17 || count1==18|| count1==19||count1==20||count1==21||count1==22||count1==23||count1==24||count1==25||count1==26||count1==27||count1==28||count1==29||count1==30||count1==31||count1==32||count1==33||count1==34||count1==35||count1==36||count1==37||count1==38||count1==39||count1==40||count1==41||count1==42||count1==43||count1==44||count1==45||count1==46 || count1==47 || count1==48|| count1==49||count1==50||count1==51||count1==52||count1==53||count1==54||count1==55||count1==56||count1==57||count1==58||count1==59||count1==60 || count1==61 || count1==62||count1==63||count1==64||count1==65)
{ quesno.setText("Question No :" + (i + 1));
break;
}
}
}
}
Arrays in Java are indexed from 0 and in following loop you are counting down from 64 to 1:
for (int i = q.length; i > 0; i--)
And you are trying to access non-existent item few lines below:
q[i]
You have to change your loop to:
for (int i = q.length - 1; i >= 0; i--)
I am trying to populate a list view with a select all query from a data base (1 Primary Key, and 4 attributes. what I have now is not throwing errors, but its not generating anything that is usable. Below is the query that I am using:
public List<SavedLocation> getAllLocationDescriptions() {
List<SavedLocation> locationList = new ArrayList<SavedLocation>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_LOCATIONS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
SavedLocation location = new SavedLocation();
location.setLocation(cursor.getString(0));
// Adding locationt to list
locationList.add(location);
} while (cursor.moveToNext());
}
return locationList;
}
This is my list view activity. (note: the log output is writing the correct results, so that seems to be working)
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class SavedLocationsListTest extends ListActivity{
#Override
public void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent intent = getIntent();
DatabaseHandler db = new DatabaseHandler(this);
List<SavedLocation> test = db.getAllLocationDescriptions();
for (SavedLocation cn : test){
String log = "ID: "+ cn.getID()+ ", Location:" + cn.getLocation() + ", Accuracy:"+ cn._accuracy+ ", Description: " +cn._description+ ", Provider:" + cn.getProvider();
Log.d("Location: ", log);}
setListAdapter (new ArrayAdapter<SavedLocation>(this, R.layout.list_test,test));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
}
}
and this is my xml layout
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textView0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</TextView>
and now as I said, I'm not getting errors, but I feel like what I am getting is even more frustrating; I have 4 records in my database and this is what I keep getting as the output when running the app:
com.example.gpstest1.SavedLocation#41eb8128
com.example.gpstest1.SavedLocation#41eb8218
com.example.gpstest1.SavedLocation#41eb8270
com.example.gpstest1.SavedLocation#41eb82c8
it looks like I'm able to populate the list view, I'm just doing it wrong.
The reason your TextViews are displaying information like com.example.gpstest1.SavedLocation#41eb8128 is that you haven't overriden the toString() method in your SavedLocation class.
The ArrayAdapter class has no idea how to convert your Java objects into a readable format. It can't read your mind and determine what a valid textual representation of a SavedLocation might be. The best it can do is call toString() on your object and hope for the best.
According to the Object.toString() documentation, the default implementation of toString() does this:
The toString method for class Object returns a string consisting of
the name of the class of which the object is an instance, the at-sign
character `#', and the unsigned hexadecimal representation of the hash
code of the object. In other words, this method returns a string equal
to the value of: getClass().getName() + '#' + Integer.toHexString(hashCode())
You have a few options. The easiest is to just override toString() in your SavedLocation and have it output what you want. This will work well if you really just want a single TextView to represent each entry.
If you want a more complicated layout, you will want to create your own ArrayAdapter subclass that overrides getView() to generate the appropriate View for each row in the ListView.
well I ended up changing:
#Override
public void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent intent = getIntent();
DatabaseHandler db = new DatabaseHandler(this);
List<SavedLocation> test = db.getAllLocationDescriptions();
for (SavedLocation cn : test){
String log = "ID: "+ cn.getID()+ ", Location:" + cn.getLocation() + ", Accuracy:"+ cn._accuracy+ ", Description: " +cn._description+ ", Provider:" + cn.getProvider();
Log.d("Location: ", log);}
setListAdapter (new ArrayAdapter<SavedLocation>(this, R.layout.list_test,test));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
to:
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.list_main);
Intent intent = getIntent();
displayList();
}
public void displayList(){
Cursor cursor=db.getAllLocationsCursor();
String from [] = new String[] {db.COLUMN_DESCRIPTION, db.COLUMN_LOCATION, db.KEY_ID};
int to [] = new int[]{R.id.textView1, R.id.textView2, R.id.textView3 };
dataAdapter = new SimpleCursorAdapter(this, R.layout.row_item, cursor, from, to, 0);
ListView lv = getListView();
lv.setAdapter(dataAdapter);
}
If I have the terminology correct, I'm using a "cursor adapter" to accomplish this...?
This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 9 years ago.
While comparing the content of sms with text, it's not working. Can any one please help me solve this? Here I want the count of a and b based on sms content. If sms content is a, it will give count 1. If another sms also has content a, then count must be incremented to 1 i.e., 2. Below is my code:
package com.example.sms;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
public class Sms extends Activity {
int count=0;
int count1=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
TextView view1 = (TextView)findViewById(R.id.textview1);
TextView view2 = (TextView)findViewById(R.id.textView2);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
String sms = "";
String data = null;
while (cur.moveToNext()) {
sms =cur.getString(12);
if(sms=="a"){
count=count+1;
view1.setText("a"+count+")");
}
else if(sms=="b"){
count1=count1+1;
view2.setText("a("+count+")");
}
else{
//view1.setText("no data");
}
//data.add(cur.getString(12));
// view1.setText(cur.getString(12));
}
//view1.setText(sms);
//setContentView(view);
}
}
The String class in Java is not a primitive type. Because of this, the == operator will not give you the results you expect- it will compare memory addresses, not the contents of the Strings.
You should use the equals() method of the String class to compare strings.
In this case, you would use:
if (sms.equals("a") {
// ...
}
Your comparison isn't working because you need to use .equals() to compare strings.
if (sms.equals("a")){
count = count + 1;
view1.setText("a" + count + ")");
}
else if (sms.equals("b")){
count1 = count1 + 1;
view2.setText("a(" + count + ")");
}
use .equals() instead of == for strings
I'm currently trying to write an app to calculate BMI and calories needed by a person (male / female).
My apps have 2 parts:
1. BMI calculation
2. Calories needed
The first part works well (so I excluded the code for this part), but for the 2nd part, calories needed calculation, it is not able to show up the result as expected (after I click on 'calories needed' button). Probably something is still missing but I cant find it so far.
Everything looks fine in the code, no error.
Can anyone help to have a look on it? :) thanks in advance.
Code as below:
package com.example.caloriescalculator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.RadioButton;
public class BMIcalculation extends Activity
{
EditText weightE;
EditText heightE ;
EditText ageE ;
TextView caloriesresult ;
RadioButton male;
RadioButton female;
Button calories;
EditText weightText ;
EditText heightText ;
EditText ageText;
TextView resultText;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.bmilayout_main);
weightE = (EditText)findViewById(R.id.weightText);
heightE = (EditText)findViewById(R.id.heightText);
ageE = (EditText)findViewById(R.id.ageText);
caloriesresult = (TextView)findViewById(R.id.caloriesText);
male = (RadioButton) findViewById(R.id.maleradio);
female = (RadioButton) findViewById(R.id.femaleradio);
Button calories = (Button) findViewById(R.id.caloriesButton);
calories.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0)
{
int caloriesneed = 0, weight = 0, height = 0, age = 0;
try {
if ((!weightE.equals("")) && (!heightE.equals("")) && (!ageE.equals("")))
{
weightE = (EditText) findViewById(R.id.weightText);
weight = Integer.parseInt(weightE.getText().toString().trim());
heightE = (EditText) findViewById(R.id.heightText);
height = Integer.parseInt(heightE.getText().toString().trim());
ageE = (EditText) findViewById(R.id.ageText);
age = Integer.parseInt(ageE.getText().toString().trim());
if (male.isSelected())
{
caloriesneed = (int) Math.round (655 + 9.6*weight + 1.8*height - 4.7*age);
caloriesresult.setText(caloriesneed);
}
else if (female.isSelected())
{
caloriesneed = (int) Math.round (66 + 13.7*weight + 5*height - 6.8*age);
caloriesresult.setText(caloriesneed);
}
}
}
catch (Exception k)
{ System.out.println(k);
}
}
});
}
caloriesresult.setText(caloriesneed);
This is problem. In Android if you assign pure int variable to some TextWidget, error will be thrown because Android will interpret it as resouce id of stored String in strings.xml.
So for this reason you need explicit casting. You can achieve it with concentation or an usage of String.valueOf(int value) or Integer.toString(int value) method:
textWidget.setText(Integer.toString(value)); // best approach
textWidget.setText(String.valueOf(value));
textWidget.setText("" + value);
Note: This is absolutely normal behaviour since if you are developing comercial application, usually you want to have support for more languages - and this feature requires localised Strings stored in proper XML file(s).
I guess it's because you try to input an integer to settext() which requires a string for input parameter, so you can try:
caloriesresult.setText("" + caloriesneed);
or
caloriesresult.setText(Integer.toString(caloriesneed));
or
caloriesresult.setText(String.valueOf(caloriesneed));
This is my first time working with dates in listviews. From looking through the SO and google, there are lots of resources and examples on listviews and binding dates to them. Many of the examples are of the date field only, but alluding to how to add them in with other fields. I'm either not understanding how to implement these, or everyone has a hard time with it, or both. So in that way I'm thinking starting with what I'm doing conceptually and then figuring out where my logic is wrong or can improve will help others.
I am working to display a listview with several textview fields, one of which is a formatted date. The data is stored in SQLite as yyyymmdd for sortability. (The listview is sorted by the date field using a good query in my dbadapter and that is working correctly)
I researched a bit on binding dates to listviews, and found that my simplecursoradapter wont work by itself but I need an additional CursorAdapter OR ViewBinder. Based on this example, I've started with a ViewBinder, but Not having my field populated with anything. To be clear, what I've done is kept my simplecursoradapter for the other fields, and they are functioning correctly. I then added an additional adapter with connection to the binder.
Here is the code from the activity where the listview exists:
private void fillTasks() {
Cursor tasksCursor = mDbHelper.fetchAllTasksforBatch(mRowId);
startManagingCursor(tasksCursor);
// Create an array to specify the fields we want to display in the list
String[] from = new String[]{
VDbAdapter.COLUMN_taskid,
VDbAdapter.COLUMN_tasktype,
VDbAdapter.COLUMN_taskSpecGrav,
VDbAdapter.COLUMN_taskacid
//VDbAdapter.COLUMN_taskdate
};
// and an array of the fields we want to bind those fields to
int[] to = new int[]{ R.id.TASKID,
R.id.TASKTYPE,
R.id.TASKGRAVITY,
R.id.TASKACID
//R.id.DATE
};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter tasks = new SimpleCursorAdapter(this, R.layout.tasklist_layout, tasksCursor, from, to);
setListAdapter(tasks);
String[] fromdate = new String[]{
VDbAdapter.COLUMN_taskdate
};
// and an array of the fields we want to bind those fields to
int[] todate = new int[]{
R.id.DATE
};
// SimpleCursorAdapter tasksdates = new SimpleCursorAdapter(this, R.layout.tasklist_layout, tasksCursor, fromdate, todate);
final DateViewBinder binder = new DateViewBinder(formatforddisplay, R.id.DATE);
tasks.setViewBinder(binder);
}
Here is the code from the DateViewBinder, essentially the same as from the example link above(package name is correct of course).
import java.text.SimpleDateFormat;
import java.util.Date;
import android.database.Cursor;
import android.view.View;
import android.widget.SimpleCursorAdapter.ViewBinder;
import android.widget.TextView;
public class DateViewBinder implements ViewBinder {
private SimpleDateFormat mFormat;
private int mTargetViewId;
public DateViewBinder(SimpleDateFormat formatforddisplay, int targetViewId) {
mFormat = formatforddisplay;
mTargetViewId = targetViewId;
}
public void setBinding(int from) {
mTargetViewId = from;
}
public void setFormat(SimpleDateFormat format) {
mFormat = format;
}
#Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
final int id = view.getId();
if (id == mTargetViewId) {
final String value = getLongFieldAsString(cursor, columnIndex);
if (view instanceof TextView)
setViewText((TextView)view, value);
else
throw new IllegalStateException(view.getClass().getName() + " is not a view that can be bound by this view binder (" +
DateViewBinder.class.getSimpleName() + ")");
return true;
}
return false;
}
I am getting no errors in logcat, so usually that helps me get pointed in the right direction. Any help is appreciated, with my problem and with how I've stated it (first time poster)
This was solved by passing the cursor to the DateViewBinder as a parameter. Here is the code with changes:
Fill Tasks Changes
SimpleCursorAdapter tasks =
new SimpleCursorAdapter(this, R.layout.tasklist_layout, tasksCursor, from, to);
final DateViewBinder binder = new DateViewBinder(formatforddisplay, R.id.DATE, tasksCursor);
tasks.setViewBinder(binder);
setListAdapter(tasks);
DateViewBinder Changes
public DateViewBinder(SimpleDateFormat formatfromBatchOverview, int targetViewId, Cursor taskscursor) {
mFormat = formatfromBatchOverview;
mTargetViewId = targetViewId;
cursor = taskscursor;
}