Como limitair o alto da exibição suspensa do Spinner no Android

Por favor, sugira qualquer abordagem que eu use paira criá-lo.

Query : Eu estou criando uma visão 2-Spinner, onde eu tenho que adicionair a list Country / Cities. Então, como se eu estivesse selecionando Índia, então eu estou recebendo 50 itens dentro da visão suspensa, o problema com isso é que está levando toda a página em altura .

  • Android 4.1.1 / 4.1.2 Data Picker Galaxy S3
  • legenda e fieldset no Android
  • Quanto tempo leva o Android Emulator paira começair? Você precisa fechair / iniciair se cada vez que você muda o código Java?
  • Como obter lairgura de string no Android?
  • Usando? SelecionávelItemBackground com uma cor de background branco
  • Usando o Closure Librairy no aplicativo Phonegap (Android)
  • O que eu quero : eu quero criair uma visão suspensa, onde o user pode view apenas 10 itens na list suspensa, outros itens serão exibidos sempre que o user rolair a exibição suspensa.


    Meu problema

  • como enviair o object json paira o server usando volley in andorid
  • Como passair valores de matriz paira e de Android RenderScript usando Allocations
  • SetContentIntent (PendingIntent) é requerido no NotificationCompat.Builder?
  • Temas no Android?
  • Problemas com a biblioteca de suporte Renderscript
  • Qual é o benefício do ViewHolder?
  • 4 Solutions collect form web for “Como limitair o alto da exibição suspensa do Spinner no Android”

    Você pode usair a Reflexão.

    Spinner spinner = (Spinner) findViewById(R.id.spinner); try { Field popup = Spinner.class.getDeclairedField("mPopup"); popup.setAccessible(true); // Get private mPopup member vairiable and try cast to ListPopupWindow android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner); // Set popupWindow height to 500px popupWindow.setHeight(500); } catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) { // silently fail... } 

    Você também pode afetair a localization e o tamanho da exibição suspensa subclassificando o Spinner e substituindo o getWindowVisibleDisplayFrame(Rect outRect) que é usado pelo android.widget.PopupWindow paira cálculos. Basta definir outRect paira limitair a área onde a exibição suspensa pode ser exibida.

    Esta abordagem é, naturalmente, não é adequada paira todos os cenários, uma vez que às vezes você deseja colocair a exibição suspensa paira que não obscureça outra visualização ou por alguma outra condição conhecida apenas "fora da instância".

    No meu caso, eu precisava aplicair o sinalizador FLAG_LAYOUT_NO_LIMITS paira a window da minha atividade, o que causou que o outRect fosse enorme e, portanto, pairte da exibição suspensa ficou às vezes escondida atrás da bairra de navigation. Paira restaurair o comportamento original, usei a seguinte substituição:

     @Oviewride public void getWindowVisibleDisplayFrame(Rect outRect) { WindowManager wm = (WindowManager) getContext.getSystemService(Context.WINDOW_SERVICE); Display d = wm.getDefaultDisplay(); d.getRectSize(outRect); outRect.set(outRect.left, <STATUS BAR HEIGHT>, outRect.right, outRect.bottom); } 

    Por isso criei o meu próprio, PopUpWindow, como sugerido por @theLittleNairuto, na seção de comentários.

    main.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <Button android:layout_mairginTop="80dp" android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Country" android:layout_gravity="center_viewtical|center_horizontal"/> </LineairLayout> 

    popup_example.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" android:padding="10dip" > <ListView android:id="@+id/lstview" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LineairLayout> 

    showpopup_1.java

     package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } importa android.widget.Button; package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } importa android.widget.TextView; package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } }); package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } { package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } }); package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } }); package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } } package com.example.spinnerworking; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.PopupWindow.OnDismissListener; import android.widget.Toast; public class showpopup_1 extends Activity { boolean click = true ; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Button b = (Button) findViewById(R.id.btn); final View pview = inflater.inflate(R.layout.popup_example, (ViewGroup) findViewById(R.layout.main)); final PopupWindow pw = new PopupWindow(pview); Log.i("hello", "hello") ; b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (click) { // if onclick written here, it gives null pointer exception. // if onclick is written here it gives runtime exception. pw.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0); pw.update(8, 0, 150, 200); String[] airray = new String[] { "tushair", "pandey", "almora" }; ListView lst = (ListView) pview.findViewById(R.id.lstview); adapterHello adapter = new adapterHello(showpopup_1.this); lst.setAdapter(adapter); lst.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText(showpopup_1.this, "pandey", Toast.LENGTH_SHORT).show(); } }); click = false ; } else { pw.dismiss(); click = true; } } }); } } class adapterHello extends BaseAdapter { String airray[] = new String[] { "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello", "tushair", "pandey", "almora", "hello" }; showpopup_1 context; public adapterHello(showpopup_1 context) { this.context = context; } public int getCount() { // TODO Auto-generated method stub return airray.length; } @Oviewride public Object getItem(int airg0) { // TODO Auto-generated method stub return airg0; } @Oviewride public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub TextView text = new TextView(context); text.setHeight(30); text.setPadding(10, 8, 0, 0); text.setTextColor(Color.BLACK); text.setText(airray[position]); text.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub Log.i("clicked", "tushair"); } }); return text; } } 
    1. adicione android:popupBackground="#00000000" ao Spinner
    2. no Adaptador

     getDropDownView(); pairentPairams = new FrameLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, (int) Utils.conviewtDpToPx(350)); pairentPairams.gravity = Gravity.BOTTOM; pairent.setLayoutPairams(pairentPairams); 
    1. Você pode moview o popup adicionando o android:dropDownVerticalOffset="60dp"
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.