android:spinner;选择值donot popup

时间:2017-03-29 03:25:55

标签: android android-spinner

Android:spinner:当选择值时,spinner会给出错误:W / InputEventReceiver:尝试完成输入事件但输入事件接收器已经被处理掉。“

enter code here

package com.example.yasir.ztailors;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import com.parse.LogOutCallback;
import com.parse.ParseException;
import com.parse.ParseUser;

import java.util.ArrayList;
import java.util.List;

import static com.example.yasir.ztailors.R.id.catagerious;


public class ZtailorFeeds extends AppCompatActivity implements AdapterView.OnItemSelectedListener{
    FloatingActionButton logout;
    String user;
    Spinner catageriousSpinner;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ztailor_feeds);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        logout= (FloatingActionButton) findViewById(R.id.logout);
        Intent i=getIntent();
        user=i.getStringExtra("username");
        setTitle(user+"'s Menu");
        catageriousSpinner= (Spinner) findViewById(catagerious);

        ArrayList<String> catageriousGender =new ArrayList<String>();

       catageriousGender.add("Men");
        catageriousGender.add("Women");
        catageriousGender.add("Kids");

        ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,catageriousGender);
        arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        catageriousSpinner.setAdapter(arrayAdapter);



        logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ParseUser.logOutInBackground(new LogOutCallback() {
                    @Override
                    public void done(ParseException e) {
                        if(e==null){
                            Intent i=new Intent(ZtailorFeeds.this,MainActivity.class);
                            startActivity(i);
                            Toast.makeText(getApplicationContext(),"Logged Out",Toast.LENGTH_LONG).show();
                        }
                    }
                });
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent i=new Intent(ZtailorFeeds.this,MainActivity.class);
        startActivity(i);
    }
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
try {
    Log.i("AppInfo", String.valueOf(parent.getItemAtPosition(position)));
}catch (Exception e){
    e.printStackTrace();
}
    }

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

    }
}
    enter code here

1 个答案:

答案 0 :(得分:0)

add spinner in XML 

 <Spinner
        android:id="@+id/spinner"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="224dp" />


and get in java code

 catageriousSpinner= (Spinner) findViewById(R.id.spinner);