Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
package com.example.ak.aapppcom;

import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.Spinner;

import java.util.ArrayList;


public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

Button iv;
EditText et1;
RatingBar ra1;
Spinner spn;
private SQLController SQLcon;


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

iv = (Button) findViewById(R.id.imageButton);
et1 = (EditText) findViewById(R.id.et1);
ra1 = (RatingBar) findViewById(R.id.ratingBar1);
spn = (Spinner) findViewById(R.id.spin);
spn.setOnItemSelectedListener(this);
SQLcon = new SQLController(this);
// opening database
SQLcon.open();

loadtospinner();

}

public void loadtospinner() {

Cursor c = SQLcon.readData();
ArrayList<string> al = new ArrayList<string>();

c.moveToFirst();
while (!c.isAfterLast()) {

String name = c.getString(c.getColumnIndex(DBhelper.COMMENTS));

al.add(name);

c.moveToNext();
}
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
//Toast.makeText(getApplicationContext(),"Item 1 Selected",Toast.LENGTH_LONG).show();
Intent i = new Intent(getApplicationContext(), Item1.class);
startActivity(i);
return true;
case R.id.item2:
//Toast.makeText(getApplicationContext(),"Item 2 Selected",Toast.LENGTH_LONG).show();
Intent i1 = new Intent(getApplicationContext(), Item1.class);
startActivity(i1);
return true;
case R.id.item3:
//Toast.makeText(getApplicationContext(),"Item 3 Selected",Toast.LENGTH_LONG).show();
Intent i2 = new Intent(getApplicationContext(), Item1.class);
startActivity(i2);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String getcom;
getcom = "";
int getrate;
getrate = 0;

SQLController handlerInfo = new SQLController(getBaseContext());
handlerInfo.open();
Cursor cursor = handlerInfo.readData();
if (cursor.moveToFirst()) {
do {
getcom = cursor.getString(1);
getrate = cursor.getInt(2);

} while (cursor.moveToNext());
}

handlerInfo.close();

}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}


class MyAsync extends AsyncTask<Void, Void, Void>
{


private Dialog PD;

@Override
protected Void doInBackground(Void... params)
{
String s = et1.getText().toString();
int rate = ra1.getNumStars();
// opening database
SQLcon.open();
// insert data into table
SQLcon.insertData(com, rate);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
loadtospinner();
PD.dismiss();
}
}

}

What I have tried:

i want to store the value of Edit text in to spinner. please give me the suggestion
Posted
Updated 26-Oct-17 22:34pm

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900