roomorama / AndroidCountryPicker

Other
165 stars 88 forks source link

Cannot see the list of countries in the CountryPicker #5

Closed khushboosoni closed 10 years ago

khushboosoni commented 10 years ago

Hello,

I am trying to use CountryPicker in my project under a form where a user enters his/her address. Here is my code:

public class FromMessageActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_from_message);     
    // Show the Up button in the action bar.
    //setupActionBar();

    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();

    CountryPicker picker = new CountryPicker();
    picker.setListener(new CountryPickerListener() {

        @Override
        public void onSelectCountry(String name, String code) {
            Toast.makeText(
                    FromMessageActivity.this,
                    "Country Name: " + name,
                    Toast.LENGTH_SHORT).show();

        }
    });

    transaction.replace(R.id.edt_ctry, picker);
    transaction.commit();   
}

Here is my layout file:

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@id/edt_addr2" android:background="@drawable/border_email" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="20dp" android:orientation="horizontal" >

        <EditText
            android:id="@+id/edt_city"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"                
            android:ems="10"
            android:hint="@string/city_hint"
            android:inputType="text"
            android:padding="6dp"
            android:textColor="#FFFFFF"
            android:textColorHint="#FFFFFF" />

        <EditText
            android:id="@+id/edt_state"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:ems="10"
            android:hint="@string/state_hint"
            android:inputType="text"
            android:padding="6dp"
            android:textColor="#FFFFFF"
            android:textColorHint="#FFFFFF" />

        <EditText
            android:id="@+id/edt_postcode"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:ems="10"
            android:hint="@string/postcode_hint"
            android:inputType="number"
            android:padding="6dp"
            android:textColor="#FFFFFF"
            android:textColorHint="#FFFFFF" >

            <requestFocus />
        </EditText>

        <LinearLayout
            android:id="@+id/edt_ctry"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="6dp"                
            android:orientation="vertical" >
        </LinearLayout>
    </LinearLayout>

I am unable to use the picker for selecting a country. This is how it looks:

https://dl-web.dropbox.com/get/Public/2013-12-06_10-45-59.png?w=AAC3pydTk68RUCWux6Kk5hmQYkvcxknIlKvHViYzkdU5YQ

Please guide me as I am a beginner to android programming.

Thanks, Khushboo

thomasdao commented 10 years ago

I can't view your image since it's not public. Anw, CountryPicker is only a fragment that's embedded inside the parent LinearLayout, you can try adding a background color to edt_ctry and debug the layout

khushboosoni commented 10 years ago

I have attached the screenshot with this email. I can only use log messages to debug my application as the debugger isn't working properly. If you can point out where to make changes, that will be really helpful.

Thanks, Khushboo

On Fri, Dec 6, 2013 at 3:29 PM, Thomas Dao notifications@github.com wrote:

I can't view your image since it's not public. Anw, CountryPicker is only a fragment that's embedded inside the parent LinearLayout, you can try adding a background color to edt_ctry and debug the layout

— Reply to this email directly or view it on GitHubhttps://github.com/roomorama/AndroidCountryPicker/issues/5#issuecomment-29968978 .

thomasdao commented 10 years ago

Sorry I won't support bug fix that's not specific to CountryPicker. It's best to ask on StackOverflow

khushboosoni commented 10 years ago

@thomasdao Hello Thomas, is it possible to use CountryPicker within a dialogfragment? I want to open it as a dialog when an EditText element is touched/clicked. I am a beginner in programming and need some advice. I am not sure how to do this task. If you can guide me in any way, it will be really helpful. Thanks.

thomasdao commented 10 years ago

You can show CountryPicker as dialog:

private void showCountryPicker() {
CountryPicker picker = CountryPicker.newInstance("Select Country");
        picker.setListener(new CountryPickerListener() {

                @Override
                public void onSelectCountry(String name, String code) {
                        Toast.makeText(
                                        MainActivity.this,
                                        "Country Name: " + name + " - Code: " + code
                                                        + " - Currency: "
                                                        + CountryPicker.getCurrencyCode(code),
                                        Toast.LENGTH_SHORT).show();
                }
        });

        picker.show(getSupportFragmentManager(), "COUNTRY_PICKER");
}

If you want to invoke this method when click on your editText:

editText.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        showCountryPicker();
    }
});

Btw my best advice to you is to slow down and spend some time go through the basic Android, it will save you plenty of time later.

khushboosoni commented 10 years ago

Thanks for your advice. You are right, I need to know the basics before, but I have been asked to volunteer for a charity project which has timing constraints. I am trying to do as much as I can and there is no senior developer to help, that's why I have been relying on internet and few people. Thanks a lot for your help.