android call log - android

With the following codes, the call log displayed is empty.Why is that soo??
package fypj.c;
import java.security.Provider;
import java.util.ArrayList;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public class c extends ListActivity {
private SimpleCursorAdapter myAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] column = new String[] {android.provider.CallLog.Calls.CACHED_NAME, android.provider.CallLog.Calls.DURATION, android.provider.CallLog.Calls.TYPE};
int[] names = new int[] {R.id.CLName, R.id.CLDuration, R.id.CLType};
myAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2, cursor, column, names);
setListAdapter(myAdapter);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/list"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CLName"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CLType"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CLDuration"
/>
</LinearLayout>

According to SimpleCursorAdapter,
"This constructor is deprecated.
This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader. "
Try an alternative to rule out any problem with your code.

Related

Cannot resolve symbol image_view in Wear OS project

I am getting a "cannot resolve symbol 'image_view'" and cannot figure out why.
Here is my main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dark_grey"
android:padding="#dimen/box_inset_layout_padding"
tools:context=".MainActivity"
tools:deviceIds="wear">
<android.support.v7.widget.FrameLayout
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/inner_frame_layout_padding"
app:boxedEdges="all" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/image_view" />
</android.support.v7.widget.FrameLayout>
</androidx.wear.widget.BoxInsetLayout>
and my the beginning part of my MainActivity.java:
package com.example.weartest3;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.android.gms.wearable.Asset;
import com.google.android.gms.wearable.CapabilityClient;
import com.google.android.gms.wearable.CapabilityInfo;
import com.google.android.gms.wearable.DataClient;
import com.google.android.gms.wearable.DataEvent;
import com.google.android.gms.wearable.DataEventBuffer;
import com.google.android.gms.wearable.DataItem;
import com.google.android.gms.wearable.DataMap;
import com.google.android.gms.wearable.DataMapItem;
import com.google.android.gms.wearable.MessageClient;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.Wearable;
import java.io.InputStream;
import java.util.concurrent.ExecutionException;
public class MainActivity extends WearableActivity implements DataClient.OnDataChangedListener,
MessageClient.OnMessageReceivedListener,
CapabilityClient.OnCapabilityChangedListener {
private TextView mTextView;
private ImageView mImageView;
private static final String IMAGE_KEY = "image";
private static final String TEXT_KEY = "text";
private static final String TAG="MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.text);
mImageView = (ImageView) findViewById(R.id.image_view);
// Enables Always-on
setAmbientEnabled();
}
The line:
mImageView = (ImageView) findViewById(R.id.image_view); is showing image_view in red and that's where the error is.
I notice it does not autofind .text in:
mTextView = (TextView) findViewById(R.id.text);
but it is not showing in red.
I also had problems with:
app:boxedEdges="all"
until I added:
android.support.v7.widget
in:
Which seems strange to me, but that will be a different post.

onListItemClick not being invoked

I am following a online course and I can across this exercise that for some reason is not working. The onListItemClick() is not being invoked. I have tried troubleshooting this but I couldn't get rid of the issue
Please help me solve this issue.
My code for MainActivity.java is
package hk.ust.cse.comp107x.greetfriend;
import android.app.ListActivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends ListActivity{
String names[];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
names=getResources().getStringArray(R.array.friends);
//setListAdapter((ListAdapter)new ArrayAdapter<String>(this,R.layout.friend_item,names));
setListAdapter( new ArrayAdapter<String>(this, R.layout.friend_item, names));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent in=new Intent(this,ShowMessage.class);
in.putExtra("message","Good Day "+names[(int) id]+"!!");
startActivity(in);
}
}
Code for ShowMessage.java is
package hk.ust.cse.comp107x.greetfriend;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class ShowMessage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_message);
Intent in=getIntent();
String message=in.getStringExtra("message");
TextView textMessage=(TextView)findViewById(R.id.textMessage);
textMessage.setText(message);
}
}
My code for friend.xml is
<?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="match_parent"
android:text="Friend Name"
android:gravity="center_vertical|center_horizontal"
android:autoText="true"
android:textSize="24sp"
android:padding="20dp"
android:id="#+id/textview">
</TextView>
And finally my code for strings.xml is
<resources>
<string name="app_name">GreetFriend</string>
<string-array name="friends">
<item>John</item>
<item>Paul</item>
<item>George</item>
<item>Ringo</item>
</string-array>
</resources>
Use the following code for your Friend.xml and run the code...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView android:layout_width="match_parent" android:layout_height="match_parent"
android:text="Friend Name"
android:gravity="center_vertical|center_horizontal"
android:textSize="24sp"
android:padding="20dp"
android:id="#+id/textviewfriend">
</TextView>
</LinearLayout>

Android Activity not Responding

I have 3 activities in my app and when user press next button, next activity is shown to user, Now everything works fine except when it reaches the last activity i.e. when user presses next on 2nd last activity, an error message is shown that app has stopped working and there is no error in LogCat, following is the .java file of my Final Activity
package com.example.first;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.os.Build;
public class FinalActivity extends ActionBarActivity {
TextView name,address,phone,email,dob,matg,mati,interg,interi,graddeg,gradi,cgpa,skills;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final);
name=(TextView)findViewById(R.id.fname);
address=(TextView)findViewById(R.id.faddress);
phone=(TextView)findViewById(R.id.fphone);
email=(TextView)findViewById(R.id.femail);
dob=(TextView)findViewById(R.id.fdob);
matg=(TextView)findViewById(R.id.matricgrade);
mati=(TextView)findViewById(R.id.matricinst);
interg=(TextView)findViewById(R.id.intergrade);
interi=(TextView)findViewById(R.id.interinst);
graddeg=(TextView)findViewById(R.id.graddegree);
cgpa=(TextView)findViewById(R.id.gradcgpa);
skills=(TextView)findViewById(R.id.iskills);
Intent in=getIntent();
UserBO bo=new UserBO();
bo.name=in.getStringExtra("name");
bo.address=in.getStringExtra("address");
bo.email=in.getStringExtra("email");
bo.phone=in.getStringExtra("phone");
bo.dob=in.getStringExtra("dob");
bo.mg=in.getStringExtra("mgrade");
bo.mi=in.getStringExtra("minst");
bo.ig=in.getStringExtra("igrade");
bo.ii=in.getStringExtra("iinst");
bo.gg=in.getStringExtra("gdeg");
bo.gi=in.getStringExtra("ginst");
bo.cgpa=in.getStringExtra("cgpa");
bo.skills=in.getStringExtra("skills");
name.setText("Name : "+bo.name);
address.setText("Address : "+bo.address);
email.setText("Email : "+bo.email);
phone.setText("Phone : "+bo.phone);
dob.setText("DOB : "+bo.dob);
matg.setText("Matric Grade : "+bo.mg);
mati.setText("Institution : "+bo.mi);
interg.setText("Inter Grade : "+bo.ig);
interi.setText("Institution : "+bo.ii);
graddeg.setText("Graduation Degree : "+bo.gg);
gradi.setText("Institution : "+bo.gi);
skills.setText("Skills : "+bo.skills);
}
}
Here is the xml file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.first.FinalActivity"
tools:ignore="MergeRootFrame" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/faddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/fphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/femail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/fdob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/matricgrade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/matricinst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/intergrade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/interinst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/graddegree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/gradinst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/gradcgpa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/iskills"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/hobbies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
</FrameLayout>
Here i'm calling the final activity
package com.example.first;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.os.Build;
public class Activity2 extends ActionBarActivity {
Button next3;
EditText s1,s2,s3,s4,s5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2);
next3=(Button)findViewById(R.id.next3);
s1=(EditText)findViewById(R.id.sk1);
s2=(EditText)findViewById(R.id.sk2);
s3=(EditText)findViewById(R.id.sk3);
s4=(EditText)findViewById(R.id.sk4);
s5=(EditText)findViewById(R.id.sk5);
next3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in=getIntent();
UserBO bo=new UserBO();
bo.name=in.getStringExtra("name");
bo.address=in.getStringExtra("address");
bo.email=in.getStringExtra("email");
bo.phone=in.getStringExtra("phone");
bo.dob=in.getStringExtra("dob");
bo.mg=in.getStringExtra("mgrade");
bo.mi=in.getStringExtra("minst");
bo.ig=in.getStringExtra("igrade");
bo.ii=in.getStringExtra("iinst");
bo.gg=in.getStringExtra("gdeg");
bo.gi=in.getStringExtra("ginst");
bo.cgpa=in.getStringExtra("cgpa");
bo.skills+=s1.getText().toString()+","+s1.getText().toString()+","+s2.getText().toString()+","+s3.getText().toString()+","+s4.getText().toString()+","+s5.getText().toString();
Intent i=new Intent(getApplicationContext(),FinalActivity.class);//this,same
System.out.println(bo.name);
i.putExtra("name", bo.name);
i.putExtra("address", bo.address);
i.putExtra("email", bo.email);
i.putExtra("phone", bo.phone);
i.putExtra("dob", bo.dob);
i.putExtra("mgrade", bo.mg);
i.putExtra("minst", bo.mi);
i.putExtra("igrade", bo.ig);
i.putExtra("iinst", bo.ii);
i.putExtra("gdeg", bo.gg);
i.putExtra("ginst", bo.gi);
i.putExtra("cgpa", bo.cgpa);
i.putExtra("skills", bo.skills);
startActivity(i);
}
});
}
Here is Activity1
package com.example.first;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.os.Build;
public class Activity1 extends ActionBarActivity {
Button next2;
EditText matGrade,matInst,iGrade,iInst,gDegree,gInst,gCgpa;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity1);
next2=(Button)findViewById(R.id.next2);
matGrade=(EditText)findViewById(R.id.mgrade);
matInst=(EditText)findViewById(R.id.minst);
iGrade=(EditText)findViewById(R.id.igrade);
iInst=(EditText)findViewById(R.id.iinst);
gDegree=(EditText)findViewById(R.id.gdegree);
gInst=(EditText)findViewById(R.id.ginst);
gCgpa=(EditText)findViewById(R.id.cgpa);
next2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in=getIntent();
UserBO bo=new UserBO();
bo.name=in.getStringExtra("name");
bo.address=in.getStringExtra("address");
bo.email=in.getStringExtra("email");
bo.phone=in.getStringExtra("phone");
bo.dob=in.getStringExtra("dob");
bo.mg=matGrade.getText().toString();
bo.mi=matGrade.getText().toString();
bo.ig=iGrade.getText().toString();
bo.ii=iGrade.getText().toString();
bo.gg=gDegree.getText().toString();
bo.gi=gDegree.getText().toString();
bo.cgpa=gDegree.getText().toString();
Intent i=new Intent(getApplicationContext(),Activity2.class);//this,same
i.putExtra("name", bo.name);
i.putExtra("address", bo.address);
i.putExtra("email", bo.email);
i.putExtra("phone", bo.phone);
i.putExtra("dob", bo.dob);
i.putExtra("mgrade", bo.mg);
i.putExtra("minst", bo.mi);
i.putExtra("igrade", bo.ig);
i.putExtra("iinst", bo.ii);
i.putExtra("gdeg", bo.gg);
i.putExtra("ginst", bo.gi);
i.putExtra("cgpa", bo.cgpa);
startActivity(i);
}
});
}
}
Here is the main Activity
package com.example.first;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
Button next1;
EditText name,address,email,phone,date;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
next1=(Button)findViewById(R.id.next1);
name=(EditText)findViewById(R.id.name);
address=(EditText)findViewById(R.id.address);
email=(EditText)findViewById(R.id.email);
phone=(EditText)findViewById(R.id.phone);
date=(EditText)findViewById(R.id.date);
next1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
UserBO bo=new UserBO();
bo.name=name.getText().toString();
bo.address=address.getText().toString();
bo.email=email.getText().toString();
bo.phone=phone.getText().toString();
bo.dob=date.getText().toString();
Intent i=new Intent(getApplicationContext(),Activity1.class);//this,same
i.putExtra("name", bo.name);
i.putExtra("address", bo.address);
i.putExtra("email", bo.email);
i.putExtra("phone", bo.phone);
i.putExtra("dob", bo.dob);
startActivity(i);
}
});
}
}
Please help me find the mistake
I think you have null pointer exception. Maybe one of your controls is missed in your xml layout. For example you are finding "next1" in your code and using its setOnClickListener method while it is not defined in you xml layout so its object is null.
I recommend you put the content of onCreate method in a try-catch and debug your application.

Android - Spinner, onItemSelected(...) not being called

Here's the code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONObject;
import com.project.locationapp.model.Device;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class SelectDevice extends Activity implements OnItemSelectedListener {
private Spinner deviceSpinner;
private List<Device> deviceList;
private ArrayAdapter<Device> deviceAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_device);
deviceList = new ArrayList<Device>();
try {
deviceSpinner = (Spinner) findViewById(R.id.select_device_spinner);
deviceAdapter = new DeviceAdapter(this, android.R.layout.simple_spinner_dropdown_item, deviceList);
deviceSpinner.setAdapter(deviceAdapter);
deviceSpinner.setOnItemSelectedListener(this);
DataAsyncTask loadDevices = new DataAsyncTask();
loadDevices.execute(new String[] { WebServiceURL.WEB_SERVICE + WebServiceURL.DEVICES + WebServiceURL.ALL });
} catch (Exception e){
Log.e(TAG, e.getLocalizedMessage(), e);
}
}
#Override
public void onItemSelected(AdapterView<?> a, View v, int position,
long id) {
Log.d(TAG, "called!");
Intent intent = new Intent(this, ViewTrips.class);
intent.putExtra("device_id", deviceAdapter.getItem(position).getId());
startActivity(intent);
}
}
DeviceAdapter class:
import java.util.List;
import com.project.locationapp.model.Device;
import android.content.Context;
import android.widget.ArrayAdapter;
public class DeviceAdapter extends ArrayAdapter<Device> {
public DeviceAdapter(Context context, int textViewResourceId,
List<Device> objects) {
super(context, textViewResourceId, objects);
}
}
Activity layout xml:
<RelativeLayout 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=".SelectDevice" >
<TextView
android:id="#+id/instructions_device_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/select_device_instructions"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp" />
<Button
android:id="#+id/start_service_button"
android:layout_below="#id/instructions_device_select"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="thisDevice"
android:text="#string/this_device"
android:layout_marginTop="10dp"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp" />
<Spinner
android:id="#+id/select_device_spinner"
android:layout_below="#id/start_service_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/select_device"
android:layout_marginTop="20dp"
android:layout_marginLeft="5dp"
android:drawSelectorOnTop = "true" />
</RelativeLayout>
I am waiting to get this working properly, then I am going to customise DeviceAdapter further.
The Activity implements OnItemSelectedListener, hence the override of onItemSelected(...), which isn't being called at all. No errors in LogCat. Spinner is defined in the Activity's layout xml and displays and populates fine. Any advice to fix this would be great.
Thank you.
It might be the spinner layouts, I can see you didn't set a dropdown view for the adapter.
Could you try to initialize your spinner like this:
deviceAdapter = new DeviceAdapter(this, android.R.layout.simple_spinner_item, deviceList);
deviceSpinner.setAdapter(deviceAdapter);
deviceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
deviceSpinner.setOnItemSelectedListener(this);
I was facing the same problem today. Then I realized I am testing on emulator. When I tested the same app it worked. I am posting this if someone is trying to get call back for spinner over emulator it did not work for me. you may also check the same. It works on real device

EditText with history

I want to show the history of text introduced in a TextView. It should be something similar to the search bar on google play:
By the moment I'm using an AutoCompleteTextView with android:completionThreshold="1", but I would like to don't need to write any text before suggestions starts.
Any ideas??
Try this its working fine:
MainActivity.java
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.os.Build;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
// In the onCreate method
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
textView.setAdapter(adapter);
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="AutoCompleteTextView" >
<requestFocus />
</AutoCompleteTextView>
</LinearLayout>

Categories

Resources