Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In this activity I have 3 buttons and 1 radiogroup.
- The radiogroup is to set the order. ASC or DESC
- Button one is to show an alertdialog where the user picks one option
- Button two is to show an alertdialog where the user picks another option
- Button three is to set the search on the database with the choices made above
- This is the code on the manifest (removed all that wasn't important)
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.stack"
- android:installLocation="auto"
- android:versionCode="1"
- android:versionName="1.0.1" >
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="15" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <supports-screens android:anyDensity="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" />
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name" >
- ........
- <activity
- android:name=".MyClass"
- android:exported="false"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <intent-filter>
- <action android:name="android.intent.action.MYCLASS" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
- .......
- </application>
- </manifest>
- After all the modifications here is the code of MyClass
- public class MyClass extends ListActivity {
- // Cria a base de dados
- Database db = new Database(this);
- ListView listContent;
- Cursor query;
- MyAdapt cursorAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.mylayout);
- // Sets my buttons and everithyng else
- // Button 1 - alertdialog that showns items so that the user picks one
- pickButOne.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- AlertDialog.Builder pickButOne = new AlertDialog.Builder(this);
- pickButOne.setTitle(...);
- pickButOne.setMultiChoiceItems(..., null, new DialogInterface.OnMultiChoiceClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which, boolean isChecked) {
- // Some code
- }
- });
- pickButOne.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // Some code
- }
- });
- pickGroup.show();
- }
- });
- // Button 2 - alertdialog that showns items so that the user picks one
- pickButTwo.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(...));
- builder.setSingleChoiceItems(..., ..., new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int item) {
- // Some code
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- }
- });
- // RadioGroup choice
- pickOrder.setOnCheckedChangeListener(new OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup group, int checkedId) {
- switch (checkedId) {
- case R.id.procOrderASC:
- order = 0;
- queryData[2] = "ASC";
- break;
- case R.id.procOrderDSC:
- order = 1;
- queryData[2] = "DESC";
- break;
- }
- }
- });
- // Button 3 - performs the search on the database with the user choices
- search.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // The result from this query is shown on the listview. After the search made if I rotate the phone, the layout kicks in (have two layouts, one for each orientation)
- db.open();
- query = db.getData(.....);
- cursorAdapter = new MyAdapt(this, query);
- listContent.setAdapter(cursorAdapter);
- db.close();
- }
- });
- }
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
- // After the listview is shown, item picks one item and the data in this item is passed to another activity
- Cursor somequery = (Cursor) getListView().getItemAtPosition(position);
- Intent i = new Intent(this, AnotherClass.class);
- i.putExtra("Test", somequery.getFloat(0));
- startActivity(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement