Hi I working with my android, I have two spinners and using retrofit to populate my spinners. I manage to populate first spinner. But I don't know how to get my second spinner populated under id selected from first spinner. I'm using codeigniter rest controller to pass the id and want to retrieve it using retrofit for second spinner, but I don't know how to do this? Please help me.
I already created Rest Controller by passing the id. Already created ApiInterface. And beans to get details data. First spinner working good.
Declaration
classSpinner = (Spinner) findViewById(R.id.classSpinner);
divSpinner = (Spinner) findViewById(R.id.divSpinner);
classSpinner.setAdapter(mAdapter);
mApiInterface = ApiClient.getClient().create(ApiInterface.class);
getAllProvinsi();
ApiInterface
public interface ApiInterface {
//first spinner
#GET("Testpage/provinsi")
Call<GetProvinsi> getProvinsi();
//second spinner that I needed how to pass the id? and get data by id selected from first spinner
#GET("Testpage/kotabyprovid/provinsi_id/")
Call<GetKota> getKota();
}
GetProvinsi ( First Spinner )
public class GetProvinsi {
#SerializedName("result")
List<Provinsi> listDataProvinsi;
public List<Provinsi> getListDataProvinsi() {
return listDataProvinsi;
}
public void setListDataProvinsi(List<Provinsi> listDataProvinsi) {
this.listDataProvinsi = listDataProvinsi;
}
}
GetKota ( Second Spinner )
public class GetKota {
#SerializedName("result")
List<Kota> listDataKota;
public List<Kota> getListDataKota() {
return listDataKota;
}
public void setListDataKota(List<Kota> listDataKota) {
this.listDataKota = listDataKota;
}
}
First Spinner to get all data. I'm trying to select the id to populate second spinner from the adapter.
private void getAllProvinsi() {
Call<GetProvinsi> kontakCall = mApiInterface.getProvinsi();
kontakCall.enqueue(new Callback<GetProvinsi>() {
#Override
public void onResponse(Call<GetProvinsi> call, Response<GetProvinsi>
response) {
List<Provinsi> ProvinsiList = response.body().getListDataProvinsi();
Log.d("Retrofit Get", "Jumlah data Kontak: " +
String.valueOf(ProvinsiList.size()));
//mAdapter = new KontakAdapter(KontakList, getBaseContext());
mAdapter = new ProvinsiAdapter(ProvinsiList, getBaseContext(), new ProvinsiAdapter.DetailsAdapterListener() {
#Override
public void classOnClick(View v, int position) {
//showClass(mTrainDetails, position);// do something or navigate to detailed classes
}
#Override
public void daysOnClick(View v, int position) {
//showDays(movieList, position);// do something or navigate to running days
}
});
classSpinner.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
}
#Override
public void onFailure(Call<GetProvinsi> call, Throwable t) {
Log.e("Retrofit Get", t.toString());
}
});
First Spinner adapter implement with OnItemSelectedListner that I need help with the method what should be?
public class ProvinsiAdapter extends BaseAdapter implements AdapterView.OnItemSelectedListener {
private LayoutInflater inflater;
List<Provinsi> mProvinsiList;
public ProvinsiAdapter.DetailsAdapterListener onClickListener;
public ProvinsiAdapter(List<Provinsi> provinsiList, Context context, ProvinsiAdapter.DetailsAdapterListener listener) {
inflater = LayoutInflater.from(context);
this.mProvinsiList = provinsiList;
this.onClickListener = listener;
}
public int getCount() {
// TODO Auto-generated method stub
return mProvinsiList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView == null){
convertView = inflater.inflate(R.layout.lsv_provinsi_list, null);
holder = new ViewHolder();
holder.txtMenuName = (TextView) convertView.findViewById(R.id.tv_namaProv);
holder.txtQuantity = (TextView) convertView.findViewById(R.id.tv_idProv);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.txtMenuName.setText(mProvinsiList.get(position).getNamaProvinsi());
holder.txtQuantity.setText(String.valueOf(mProvinsiList.get(position).getId()));
return convertView;
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Please help what should I put in here to populate second spinner
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
static class ViewHolder {
TextView txtMenuName, txtQuantity, txtPrice;
}
//region Interface Details listener
public interface DetailsAdapterListener {
void classOnClick(View v, int position);
void daysOnClick(View v, int position);
}
}
JSON Result with id Testpage/kotabyprovid/provinsi_id/1 for second spinner
{"result":[{"id_kota":"17","provinsi_id":"1","nama_kota":"Badung"},{"id_kota":"32","provinsi_id":"1","nama_kota":"Bangli"},{"id_kota":"94","provinsi_id":"1","nama_kota":"Buleleng"},{"id_kota":"114","provinsi_id":"1","nama_kota":"Denpasar"},{"id_kota":"128","provinsi_id":"1","nama_kota":"Gianyar"},{"id_kota":"161","provinsi_id":"1","nama_kota":"Jembrana"},{"id_kota":"170","provinsi_id":"1","nama_kota":"Karangasem"},{"id_kota":"197","provinsi_id":"1","nama_kota":"Klungkung"},{"id_kota":"447","provinsi_id":"1","nama_kota":"Tabanan"}],"0":200}
Please help and Thank You
Replace
#GET("Testpage/kotabyprovid/provinsi_id/")
Call<GetKota> getKota();
with
#GET("Testpage/kotabyprovid/provinsi_id/{prov_id}")
Call<GetKota> getKota(#Path("prov_id") int provId);
Now you can pass id to the method, the retrofit will take care of passing provId to the URL path.
Related
How to hide an item from other spinners that is currently selected in one spinner?
I've tried removing the items via ArrayList of strings and ArrayAdapters, but I've noticed as soon as it's removed from the list, the selection is no longer referenced to the list item (because it does not exist anymore).
Now suppose, I have 4 spinner that are created dynamically and they all have the same ArrayList as their resource and now i would like to use this adapter to fetch the position of the selected item from 1 spinner and then hide it from 3 other spinners.
for (int i = 0; i < numberOfStops; i++) {
AddStopView stopView = new AddStopView(getActivity());
stopView.setCallback(BaseBookingFragment.this);
stopView.setPassengerNames(extraPassengerNames);
stopViews.add(stopView);
parent.addView(stopView, viewPosition);
}
In above code i am creating Stop Views dynamically and each Stop View having Passenger Name spinner. And these all spinners have the same ArrayList as their resource.
piece of code from AddStopView.java
public AddStopView(Context context) {
super(context);
initialize();
}
public void setCallback(StopViewCallback callback) {
this.callback = callback;
}
public void setPassengerNames(List<String> passengerNames) {
this.passengerNames = passengerNames;
passengerAdapter.setNames(passengerNames);
}
private void initialize() {
inflate(getContext(), R.layout.view_stop, this);
passengerAdapter = new ExtraPassengerAdapter(getContext());
passengerAdapter.setNames(passengerNames);
nameSpinner.setAdapter(passengerAdapter);
nameSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (view == null) {
return;
}
passengerName = (String) view.getTag();
if (position != 0)
callback.updatePassengerList(AddStopView.this, (position - 1));
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
code of call back of nameSpinner.setOnItemSelectedListener
#Override
public void updatePassengerList(AddStopView addStopView, int position) {
for (String passName : extraPassengerNames) {
if (addStopView.getPassengerName().equals(passName)) {
extraPassengerNames.remove(passName);
break;
}
}
for (AddStopView stopView : stopViews) {
if (!stopView.equals(addStopView))
stopView.setPassengerNames(extraPassengerNames);
}
}
code from ExtraPassengerAdapter.java
public class ExtraPassengerAdapter extends BaseAdapter {
private List<String> names = new ArrayList<>();
private Context context;
public ExtraPassengerAdapter(Context context) {
this.context = context;
names.add(get0Position());
}
public void setNames(List<String> names) {
this.names.clear();
this.names.add(get0Position());
this.names.addAll(names);
notifyDataSetChanged();
}
#Override
public int getCount() {
return names.size();
}
#Override
public String getItem(int position) {
return names.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_stop, parent, false);
String name = getItem(position);
textView.setText(name);
textView.setTag(name);
return textView;
}
private String get0Position() {
return context.getString(R.string.passenger_name);
}
}
I think the right way to solve you problem is to create one list with all possible options and 4 lists with 4 adapters for each spinner. When something selected you update each list according to logic you described and call adapter.notifyDataSetChanged() for each adapter.
I have implemented a ListView. From ListView I am adding a products to cart. My problem is if i add a first product i am changing a button name Addtocart to Added if i scroll ListView 4th position product button name is changing to Added.
How can I resolve this ?
Here my code:
holderForGrid.AddtoCart.setTag(position);
holderForGrid.AddtoCart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
holderForGrid.AddtoCart.setText("Added");
}
});
Adapter Class:
class ListAdapter extends BaseAdapter {
public Context context;
public ListAdapter(Context a,List<BusinessCatalogVariables> listDataHeader) {
this.listDataHeader = listDataHeader;
context = a;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return catalogList.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
#Override
public View getView(final int position, View convertView, ViewGroup arg2) {
final ViewHolderGrid holderForGrid;
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.catalog_list_item, null);
holderForGrid = new ViewHolderGrid(convertView);
convertView.setTag(holderForGrid);
} else {
holderForGrid = (ViewHolderGrid) convertView.getTag();
}
finalCatalogVariables Catalog = catalogList.get(position);
holderForGrid.AddtoCart.setClickable(false);
holderForGrid.AddtoCart.setTag(position);
holderForGrid.AddtoCart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
int position1=(Integer)arg0.getTag();
AddedProduct = (String) holderForGrid.CatalogHeader.getText();
holderForGrid.AddtoCart.setText("Added");
}
});
return convertView;
}
private class ViewHolderGrid {
Button AddtoCart = null;
ViewHolderGrid(View convertView) {
AddtoCart = (Button) convertView.findViewById(R.id.btn_AddtoCart);
}
}
}
create boolean variable added in finalCatalogVariables class.
and create getter,setter method for this variable.
like,
class finalCatalogVariables{
// other variable and methods
boolean added;
public boolean isAdded()
{
return this.added;
}
public void setAdded(boolean added){
this.added = added;
}
}
then in getView method on click of holderForGrid.AddtoCart
public View getView(final int position, View convertView, ViewGroup arg2) {
final ViewHolderGrid holderForGrid;
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.catalog_list_item, null);
holderForGrid = new ViewHolderGrid(convertView);
convertView.setTag(holderForGrid);
} else {
holderForGrid = (ViewHolderGrid) convertView.getTag();
}
finalCatalogVariables catalog = catalogList.get(position);
if(catalog.isAdded()){
holderForGrid.AddtoCart.setText("Added");
}else{
holderForGrid.AddtoCart.setText("Add to cart");
}
holderForGrid.AddtoCart.setClickable(false);
holderForGrid.AddtoCart.setTag(position);
holderForGrid.AddtoCart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
catalog.setAdded(true);
int position1=(Integer)arg0.getTag();
AddedProduct = (String) holderForGrid.CatalogHeader.getText();
// holderForGrid.AddtoCart.setText("Added");
}
});
return convertView;
}
Override below mentioned two methods in your adapter class.
Override
public int getViewTypeCount() {
return getCount();
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.rowlayout, null);
if (imageLoader == null)
imageLoader = Session.getInstance().getImageLoader();
//write your declaration code
List m = Yourarray.get(position);
// thumbnail image
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your code
int position1=(Integer)arg0.getTag();
AddedProduct = (String) holderForGrid.CatalogHeader.getText();
holderForGrid.AddtoCart.setText("Added");
}
});
return convertView;
}
I think the problem is that if you change the button on a view and then scroll far enough for the view to disappear, Android will assign the view position to another item in the listView.
You need to maintain somehow the status "added" or not of each product and let your adapter decide what label to display based on that.
I have a list view and each item contains a check box and other various text views. In the Main Activity I have an ArrayList of objects called listOfStuff. From the main activity I'm defining and using a custom base adapter. In the getView method I defined a listener for the check box like so:
holder.cbCompletionStatus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(holder.cbCompletionStatus.isChecked()){
listOfStuff.get(position).setComplete(1);
} else {
listOfStuff.get(position).setComplete(0);
};
}
});
My problem is that I don't know how to access the listOfStuff and the objects within it to modify the information within. The code in the if/else statement hopefully gives an idea what I was trying to do. Just a quick warning, I'm not only new to Android and Java, but to programming field on the whole. Thanks.
UPDATE:
So I ended up figuring this out on my own. I just had to make the listOfStuff Arraylist a static in the Main Activity. Then I could call a static function in the Main Activity to manipulate whatever data in the Array list I needed like so:
MainActivity.checkBoxClicked(result, position);
Here is my class:
class ImageInfoAdapter extends BaseAdapter{
#Override
public int getCount() {
if(viewcount == 0){
return 0;
}
return viewcount;
}
#Override
public Object getItem(int position) {
return isSentAlList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
final ViewHolder viewHolder;
View rowView=view;
if(rowView==null){
LayoutInflater layoutinflate = LayoutInflater.from(ListPictures.this);
rowView=layoutinflate.inflate(R.layout.listviewayout, parent, false);
viewHolder = new ViewHolder();
viewHolder.textViewisSentFlag = (TextView)rowView.findViewById(R.id.textViewisSentFlag);
viewHolder.imageViewToSent = (ImageView)rowView.findViewById(R.id.imageViewToSent);
viewHolder.checkBoxToSend = (CheckBox)rowView.findViewById(R.id.checkBoxToSend);
rowView.setTag(viewHolder);
} else{
viewHolder = (ViewHolder) rowView.getTag();
}
viewHolder.ref = position;
Log.i("InfoLog","viewHolder.ref = position; "+viewHolder.ref);
viewHolder.textViewisSentFlag.setText(isSentAlList.get(position));
Bitmap blob = BitmapFactory.decodeByteArray(imageAlList.get(position), 0, imageAlList.get(position).length);
viewHolder.imageViewToSent.setImageBitmap(blob);
viewHolder.checkBoxToSend.setClickable(true);
if(checked.containsKey(""+viewHolder.ref)){ ///if this id is present as key in hashmap
Log.i("InfoLog","checked.containsKey "+viewHolder.ref);
if(checked.get(""+viewHolder.ref).equals("true")){ //also check whether it is true or false to check/uncheck checkbox
Log.i("InfoLog","checked.get(position) "+viewHolder.ref);
viewHolder.checkBoxToSend.setChecked(true);
} else
viewHolder.checkBoxToSend.setChecked(false);
} else
viewHolder.checkBoxToSend.setChecked(false);
viewHolder.checkBoxToSend.setOnCheckedChangeListener(new OncheckchangeListner(viewHolder));
return rowView;
}//End of method getView
}//End of class ImageInfo
class ViewHolder{
private TextView textViewisSentFlag = null;
private ImageView imageViewToSent = null;
private CheckBox checkBoxToSend = null;
int ref;
}//End of class ViewHolder
/////////////////////////
and here is my oncheckchangedlistener
////////////////////////
class OncheckchangeListner implements OnCheckedChangeListener{
ViewHolder viewHolder = null;
public OncheckchangeListner(ViewHolder viHolder) {
viewHolder = viHolder;
}
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(viewHolder.checkBoxToSend.equals(buttonView)) {
if(!isChecked) {
Log.i("InfoLog","checked.get before "+checked.get(""+viewHolder.ref));
checked.put(""+viewHolder.ref,"false");
Log.i("InfoLog","checked.get after "+checked.get(""+viewHolder.ref));
} else
checked.put(""+viewHolder.ref,"true");
} else
Log.i("InfoLog","i m in checkchange ");
}
}
I am struggling with trying to implement an OnLongClick feature - I can't understand where to add a listener and to define the resulting method.
The implementation i have used uses an adapter - and does not have an onClickListener, but works jsut fine. can anyone suggest where/how to implement OnLongClick listener
I don't need every item in the list to perform different actions - just for anywere on the screen to pick up the long press
public class CombChange extends ListActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ListEdit(this, symbols));
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String selectedValue = (String) getListAdapter().getItem(position);
if (lastPressed.equals(selectedValue) ){
count++;}
}
public class ListEdit extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public ListEdit(Context context, String[] values) {
super(context, R.layout.activity_comb_change, values);
this.context = context;
this.values = values;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_comb_change, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
textView.setText(values[position]);
// Change icon based on name
String s = values[position];
if (s.equals("a")) {
imageView.setImageResource(R.drawable.a);
return rowView;
}
}
Try this:
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
v.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
String selectedValue = (String) getListAdapter().getItem(position);
if (lastPressed.equals(selectedValue) ){
count++;}
return false;
}
});
}
It is unfortunate that a ListActivity does not have a protected onListItemLongClick() method similar to the onListItemClick() function.
Instead, you can add setOnLongClickListener() to the top-level layout item (or any View) in your adapter's getView() function.
Example:
myView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// Do something here.
return true;
}
});
Warning, the OnLongClickListener you put onto your list item may hide exposure to the onListItemClick() function you already have working for the list. If this is the case, you will also have to add setOnClickListener() to getView() and use it instead.
in your getView you can say
rowview.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View arg0) {
//Do your stuff here
return false;
}
});
I'm testing code copied from a Java Android examples site. I'm trying to modify it to start a new activity when a user clicks into a row of the current activity. So I'm using the Intent method but I'm not able to figure out how to reference the current View instance argument to the Intent method.
I've tried dozens of combinations, and spent 2 days researching. This must seem basic to many of you I know, but my apologies, this is week #2 for me learning Java, Eclipse and the Android SDK (target= API 8)
public class CustomListViewDemo extends ListActivity {
private EfficientAdapter adap;
private static String[] data = new String[] { "0", "1" };
private static String[] TitleString = new String[] { "Title1", "Title2" };
private static String[] DetailString = new String[] { "Detail1", "Detail2" };
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
adap = new EfficientAdapter(this);
setListAdapter(adap);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Toast.makeText(this, "Click-" + String.valueOf(position),
Toast.LENGTH_SHORT).show();
}
public static class EfficientAdapter extends BaseAdapter implements
Filterable {
private LayoutInflater mInflater;
private Bitmap mIcon1;
private Context context;
public EfficientAdapter(Context context) {
// Cache the LayoutInflate to avoid asking for a new one each time.
mInflater = LayoutInflater.from(context);
this.context = context;
}
/**
* Make a view to hold each row.
*
*/
public View getView(final int position, View convertView,
ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.adaptor_content, null);
holder = new ViewHolder();
holder.textLine = (TextView) convertView
.findViewById(R.id.textLine);
holder.buttonLine = (Button) convertView
.findViewById(R.id.buttonLine);
holder.DbuttonLine = (Button) convertView
.findViewById(R.id.DbuttonLine);
holder.textLine2 = (TextView) convertView
.findViewById(R.id.textLine2);
convertView.setOnClickListener(new OnClickListener() {
private int pos = position;
#Override
public void onClick(View v) {
// Toast.makeText(context, "Click-" +
// String.valueOf(pos),
// Toast.LENGTH_SHORT).show();
// ******************** ERROR IS LINE BELOW *********
// "No enclosing instance of the type CustomListViewDemo is accessible in scope"
Intent i = new Intent(CustomListViewDemo.this, IntentA.class);
startActivity(i);
}
});
holder.buttonLine.setOnClickListener(new OnClickListener() {
private int pos = position;
#Override
public void onClick(View v) {
Toast.makeText(context,
"Delete-" + String.valueOf(pos),
Toast.LENGTH_SHORT).show();
}
});
holder.DbuttonLine.setOnClickListener(new OnClickListener() {
private int pos = position;
#Override
public void onClick(View v) {
Toast.makeText(context,
"Details-" + String.valueOf(pos),
Toast.LENGTH_SHORT).show();
}
});
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
holder.textLine.setText(TitleString[position]
+ String.valueOf(position));
holder.textLine2.setText(DetailString[position]
+ String.valueOf(position));
return convertView;
}
static class ViewHolder {
TextView textLine;
TextView textLine2;
Button buttonLine;
Button DbuttonLine;
}
#Override
public Filter getFilter() {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return data.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return data[position];
}
}
}
I have seen many examples about how to refer to outer members of nested classes but not found a good example on find the view instance of an outer class for use as a method argument. Can anyone point me in the right direction?
If you look at the docs, the constructor you're invoking (new Intent(CustomListViewDemo.this, IntentA.class)), is this one:
public Intent (Context packageContext, Class<?> cls)
Since you're already storing a Context, you can fix your problem by using new Intent(this.context, IntentA.class) instead.
CustomListViewDemo.this
For this to work, you need an instance.
In a static nested class, there is no outer instance.
You have to either make the class "non-static", or explicitly pass a reference to a CustomListViewDemo instance around that you want to use here.
EfficientAdapter is a static class so you don't necessarily have an instance of CustomListViewDemo that you can use yet. Static implies that the class can be used without an instance, hence your error
"No enclosing instance of the type CustomListViewDemo is accessible in scope"
You have two options here.
1) Go with dmon's suggestion and use the context you have stored:
Intent i = new Intent(context, IntentA.class);
2) Do not make EfficientAdapter a static class (what is the reason for having it static?)