I want to display ListPopupActivity on a button click but it is throwing this exception.
I have read thoroughly about this exception but couldn’t solve the problem
There is no jar file used in the project.
Here is the class:
public class MainActivity extends Activity {
String[] listItems = {"item 1", "item 2 ", "list", "android", "item 3", "foobar", "bar", };
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@SuppressLint("NewApi")
public void onClick(View v) {
// TODO Auto-generated method stub
ListPopupWindow lpw = new ListPopupWindow(MainActivity.this);
lpw.setAdapter(new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, listItems));
lpw.setAnchorView(findViewById(R.id.btn));
lpw.setWidth(150);
lpw.setHeight(300);
lpw.show();
}
});
}
The class ListPopupWindow was added in api level 11 (os version 3.0). I think you have set the targetSdkVersion to 11 in your manifest and trying to run your project in device that runs below api level 11.