Android的微调对话框不显示? [英] Android Spinner Dialog is not Populating?

查看:217
本文介绍了Android的微调对话框不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有由两个片段的活性。左边是一个侧边栏,右边是一个图形页面(参见下图)。

I have an activity made up of two fragments. On the left is a sidebar, on the right is a MapView (See screenshot below).

在左侧我有将与地图上的对象来填充一个微调。现在,我已经很难codeD与一些值,直到我弄清楚这个问题。当选择了微调,会出现一个对话框,但它是空的。任何想法是怎么回事?

On the left I have a spinner that will be populated with objects on the map. Right Now, I have it hardcoded with some values until I figure out this issue. When the Spinner is selected, a dialog appears, but it is empty. Any idea what is going on?

下面是我的code左片段(它不是很复杂):

Here is my code for the left fragment (Its not very complex):

package android.splitdisplay;


import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

public class SideFragment extends Fragment {
    String[] tracks = { "ObjectOne", "ObjectTwo",
            "ObjectThree"

    };


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

        final Spinner s = (Spinner) this.getActivity().findViewById(
                R.id.track_spinner);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this
                .getActivity().getBaseContext(),
                android.R.layout.simple_spinner_item, tracks);
        s.setAdapter(adapter);

        s.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                int item = s.getSelectedItemPosition();
                Toast.makeText(SideFragment.this.getActivity().getBaseContext(),
                        "clicked "+item, Toast.LENGTH_SHORT).show();
            }

                @Override
            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });

    }

    public void onListItemClick(ListView parent, View v, int position, long id) {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.sidefragment, container, true);
    }
}

下面是XML的SideFragment:

Here is the XML for the SideFragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Tracks"
        android:textColor="#adff2f"
        android:textSize="30sp" />

    <Spinner
        android:id="@+id/track_spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:prompt="@string/track_prompt"
        android:spinnerMode="dialog" >
    </Spinner>

</LinearLayout>

下面就是我看到当我点击微调:

Here is what I am seeing when I click on the spinner:

下面是所有在一个zip源$ C ​​$ C的:

Here is all of the source code in a zip:

http://db.tt/KMGXhZWc

推荐答案

问题是不是微调,问题是,你夸大两个微调。一个在onCreateView方法和其他在这一行:

The problem is not the Spinner, the problem is that you are inflating two Spinners. One in on onCreateView method and the other in this line :

this.getActivity().setContentView(R.layout.sidefragment);

和唯一一家与供应商的微调...所以我建议你设定所有的GUI变量在onCreationView是这样的:

And only one the spinner with the provider... so I recommend you to set all your GUI variable at onCreationView like this:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.sidefragment, container, true);
    final Spinner s = (Spinner) v.findViewById(
            R.id.track_spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this
            .getActivity().getBaseContext(),
            android.R.layout.simple_spinner_item, tracks);
    s.setAdapter(adapter);

    s.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            int item = s.getSelectedItemPosition();
            Toast.makeText(SideFragment.this.getActivity().getBaseContext(),
                    "clicked "+item, Toast.LENGTH_SHORT).show();
        }

            @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    return v;
}

和删除overrided方法的onCreate。

And remove the overrided method onCreate.

这篇关于Android的微调对话框不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆