This example is use floating button to float over your listview
main.xml
FloatingViewExample.java
package montercodz.blogspot.com; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Toast; public class FloatingViewExample extends ListActivity implements OnClickListener { private Button btnFloat; private Button btnFloat1; String[] mStrings = new String[] {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10", "Item 11", "Item 12"}; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnFloat = (Button)findViewById(R.id.floating_button); btnFloat1 = (Button)findViewById(R.id.floating_button1); ArrayAdapteradapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, mStrings); this.setListAdapter(adapter); //set Floating button listener btnFloat.setOnClickListener(this); btnFloat1.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == btnFloat){ this.setSelection(0); Toast.makeText(getApplicationContext(), "Move to top", Toast.LENGTH_SHORT).show(); }else if(v == btnFloat1){ this.setSelection(mStrings.length-1); Toast.makeText(getApplicationContext(), "Move to buttom", Toast.LENGTH_SHORT).show(); } } }
0 comments:
Post a Comment