I have an application which has a gridview with images in it. The problem is its showing in all phones except for API 21 i.e. Lollipop version. In Lollipop its shows just background and no gridview. The targetSDK is 21 and minSDK is 8. Any help in this would be much appreciated.
MainActivity
public class MainView extends Activity {
ImageView back, home, site, header;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
setContentView(R.layout.mainview);
GridView gridView = (GridView)findViewById(R.id.gridview);
gridView.setAdapter(new MyAdapter(this));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent myIntent = null;
if(position == 0){
myIntent = new Intent(v.getContext(), TheShow.class);
}
if(position == 1){
myIntent = new Intent(v.getContext(), Exhibitor.class);
}
if(position ==2){
myIntent = new Intent(v.getContext(), Visitor.class);
}
if(position ==3){
myIntent = new Intent(v.getContext(), Conference.class);
}
if(position ==4){
myIntent = new Intent(v.getContext(), ContactUs.class);
}
if(position == 5){
myIntent = new Intent(v.getContext(), ExhibitorReg.class);
}
if(position == 6){
myIntent = new Intent(v.getContext(), VisitorReg.class);
}
if(position == 7){
myIntent = new Intent(v.getContext(), FlrPlan.class);
}
if(myIntent!=null){
startActivity(myIntent);
}
}
});
back=(ImageView)findViewById(R.id.imageView2);
home=(ImageView)findViewById(R.id.imageView3);
site=(ImageView)findViewById(R.id.imageView4);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
MainView.this.onBackPressed();
}
});
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Same Page", Toast.LENGTH_LONG).show();
}
});
site.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String url = "http://india-aviation.in/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
header=(ImageView)findViewById(R.id.imageView1);
header.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(MainView.this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("About Us");
dialog.setCancelable(true);
Button button = (Button) dialog.findViewById(R.id.buttonOK);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
}
private class MyAdapter extends BaseAdapter
{
private List<Item> items = new ArrayList<Item>();
private LayoutInflater inflater;
public MyAdapter(Context context)
{
inflater = LayoutInflater.from(context);
items.add(new Item("The Show", R.drawable.globecopy1));
items.add(new Item("Exhibitor", R.drawable.workcopy1));
items.add(new Item("Visitor", R.drawable.visitor1copy1));
items.add(new Item("Conference", R.drawable.conferencecopy1));
items.add(new Item("Contact Us", R.drawable.contactus1copy1));
items.add(new Item("Exhibitor Registration", R.drawable.exregistercopy1));
items.add(new Item("Visitor Registration", R.drawable.anothercopy1));
items.add(new Item("Layout Plan", R.drawable.registercopy1));
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int i)
{
return items.get(i);
}
@Override
public long getItemId(int i)
{
return items.get(i).drawableId;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup)
{
View v = view;
ImageView picture;
TextView name;
if(v == null)
{
v = inflater.inflate(R.layout.gridview_item, viewGroup, false);
v.setTag(R.id.picture, v.findViewById(R.id.picture));
v.setTag(R.id.text, v.findViewById(R.id.text));
}
picture = (ImageView)v.getTag(R.id.picture);
name = (TextView)v.getTag(R.id.text);
Item item = (Item)getItem(i);
picture.setImageResource(item.drawableId);
name.setText(item.name);
return v;
}
private class Item
{
final String name;
final int drawableId;
Item(String name, int drawableId)
{
this.name = name;
this.drawableId = drawableId;
}
}
}
}
If you app has a values-21 folder in res folder, either set the layout there or delete the folder if you want persistent layout for all APIs.