mardi 22 décembre 2015

How to use string array conditions from edit text in Android without using sqlite?

As we can see the codes below, I would like to retrieve the string elements from:

String[]placelist and String[]cuisinelist

without the need to delcare again in the second half of the code. I want to get a new intent (a new activity) by retrieving the string elements by clicking the GetMenu (View v) button.

NB: The EditText is in AutoViewComplete and I do not want to use SQLite Database.

Please give some solutions.

package com.example.restfinder;

import com.example.restfinder.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity
{
    String[]placelist={"Bangalore, Karnataka",
                        "New Delhi, Delhi",
                        "Chennai,Tamil Nadu",
                        "Kolkata, West Bengal",
                        "Mumbai, Maharashtra"};
    String[]cuisinelist={"American","Chinese","French","German","Indian",
                        "Italian","Japanese", "Mexican","Spanish","Thai"};

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ArrayAdapter<String>adapter=new
        ArrayAdapter<String>(getBaseContext(),android.R.layout.simple_dropdown_item_1line,placelist);
        AutoCompleteTextView tv=(AutoCompleteTextView)
                findViewById(R.id.tvPlace);
                tv.setThreshold(1);
                tv.setAdapter(adapter);

        ArrayAdapter<String>adapter1=new
        ArrayAdapter<String>(getBaseContext(),android.R.layout.simple_dropdown_item_1line,cuisinelist);
        AutoCompleteTextView tv1=(AutoCompleteTextView)
                findViewById(R.id.tvCuisine);
                tv1.setThreshold(1);
                tv1.setAdapter(adapter1);

    }


    public void GetMenu(View v)
    {
        String[]placelist={"Bangalore, Karnataka",
                "New Delhi, Delhi",
                "Chennai,Tamil Nadu",
                "Kolkata, West Bengal",
                "Mumbai, Maharashtra"};
        String[]cuisinelist={"American","Chinese","French","German","Indian",
                "Italian","Japanese", "Mexican","Spanish","Thai"};

        if((placelist.equals("Bangalore, Karnataka"))||(cuisinelist.equals("American")))                
                            {
                            startActivity(new Intent("com.example.restfinder.bangalore_american"));
                            }

------

depends on the conditions

------

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

Aucun commentaire:

Enregistrer un commentaire