Question

i'm sorry if this question is a repeat. I have a problem:

I have one main_activity with main_layout.xml. I have a TextView and SeekBar1 in it. I added a menu with a custom_dialog_layout which has a seekbar2. Dialog shows that custom_dialog with seek bar.

when doing this:

inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.resize_dialog,null);
seekbar = (SeekBar)findViewById(R.id.seekBar2);

application force closes.

Was it helpful?

Solution

Try this.

 inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 view = inflater.inflate(R.layout.resize_dialog,null); 
 seekbar = (SeekBar)view. findViewById(R.id.seekBar2); 

/** Add that inflated view to AlertDialog */

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.app_name);
    builder.setView(view);

use this for cancelling Dialog. i.e dialog.dismiss();

.setPositiveButton(
                getResources().getString(R.string.Cancel),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                            int whichButton) {
                        dialog.dismiss();
                    }
                });
        alert = builder.create();
        alert.show();

OTHER TIPS

replace with following code.

inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
view = inflater.inflate(R.layout.resize_dialog,null); 
seekbar = (SeekBar)view.findViewById(R.id.seekBar2);

you need to pass reference of view to find id.

use the below code.

    private class ViewHolder {          
    SeekBar seekbar ;

}


    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    if(convertView==null)
    {
        convertView=mInflater.inflate(R.layout.resize_dialog, null);
         holder=new ViewHolder();
         holder.seekbar = (SeekBar)convertView.findViewById(R.id.seekBar2);
         convertView.setTag(holder);
          }
      else  
    holder=(ViewHolder) convertView.getTag();


      return convertView;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top