PROBLEMSpinner zeigt den ausgewählten Artikel nicht an
Wenn ich den Code für Spinner schreibe, wird das ausgewählte Element nicht angezeigt. Es zeigt nur den Toast des ausgewählten Artikels.
public class Retailormainhomepage extends Activity implements AdapterView.OnItemSelectedListener {
EditText mname;
TextView mcategory;
EditText mproduct;
Button mupload,mproducts;
String enteredRetailorname,enteredCategory,enteredProduct;
String enteredid,enteredRetailor_name,enteredCategory_id,enteredProduct_name;
String jsonresponce=null;
String UPLOAD_URL,PRODUCTS_URL;
ProgressDialog pd;
ImageView mimageback;
InputStream is = null;
private Spinner spinner;
String result = null;
List<String> list;
boolean connection = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_retailorhomepage);
mimageback = (ImageView)findViewById(R.id.imageback);
mname = (EditText)findViewById(R.id.rname);
mcategory = (TextView)findViewById(R.id.category);
mproduct = (EditText)findViewById(R.id.product);
mupload = (Button)findViewById(R.id.upload);
spinner = (Spinner)findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(Retailormainhomepage.this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
categories.add("Automobile");
categories.add("Business Services");
categories.add("Computers");
categories.add("Education");
categories.add("Personal");
categories.add("Travel");
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
.
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
// Showing selected spinner item
Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
XML-Datei:
Dies ist meine XML-Datei für den gleichen requirement.I keine logcat Fehler bekam dafür nur ist es nicht das ausgewählte Element in Bearbeiten von Text zeigt.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_marginTop="22dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:weightSum="1">
<TextView
android:layout_width="125dp"
android:layout_height="40dp"
android:text="category"
android:id="@+id/category"
android:textColor="#000000"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:textSize="20dp"/>
<EditText
android:layout_width="173dp"
android:layout_height="40dp"
android:id="@+id/etcategory"
android:hint="1,2,..."
android:layout_marginLeft="20dp"
android:textColor="#000000"
android:layout_alignTop="@+id/textView2"
android:layout_alignParentRight="true"
android:textSize="15dp"
/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/category"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" />
</LinearLayout>
ja, ich folge dem gleichen Link, aber es wird nicht angezeigt und das ausgewählte Element muss in meiner Datenbank zusammen mit anderen Details gespeichert werden pls suggerieren mich – Mounika
[link] (http://webconnect.0fees.net/android /spinner-example.php?id=14) verweisen Sie auf diesen Link – bhadresh