Note that there are some explanatory texts on larger screens.

plurals
  1. POinflate custom Gallery Layout change properties fail
    primarykey
    data
    text
    <p>I tried to build my first custom gui element but I get problems when I try to change appearance or adapter (using Gallery) later in code.</p> <p>My Problem: I can't change Custom Gallery properties</p> <p>My actual Code:</p> <p>First I create an XML which is the widget customGallery.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;merge xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;ImageButton android:id="@+id/toLeft" android:background="@drawable/arrow_left" android:layout_width="wrap_content" android:layout_height="40dip" android:layout_marginBottom="1dip" /&gt; &lt;Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="40dip" android:layout_toRightOf="@+id/toLeft" android:spacing="40dip" android:scrollbars="horizontal"/&gt; &lt;ImageButton android:id="@+id/toRight" android:background="@drawable/arrow_right" android:layout_width="wrap_content" android:layout_height="40dip" android:layout_toRightOf="@+id/gallery" /&gt; &lt;/merge&gt; </code></pre> <p>Later i create a test.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lin_layout" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;com.Test.GallerySlider android:id="@+id/choose" android:layout_span="2" android:layout_width="300dip" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>My next Step was to include this custom Widget into my project and change the adapter from my Widget:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout lineLayout = (LinearLayout) findViewById(R.id.lin_layout); ViewStub st3 = new ViewStub(TestwidgetActivity.this); LinearLayout.LayoutParams paramst3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lineLayout.addView(st3,paramst3); st3.setLayoutResource(R.layout.test); View st3InflaView =st3.inflate(); GallerySlider gSlider= (GallerySlider) st3InflaView.findViewById(R.id.choose); gSlider.setNewAdapter( new ArrayAdapter&lt;String&gt;(this, android.R.layout.customGallery, new String[] {"1 ","2","3","4"})); } </code></pre> <p>This is the Widgetclass I wrote:</p> <pre><code> public class GallerySlider extends RelativeLayout implements OnClickListener { private ArrayAdapter&lt;String&gt; adapter; private Gallery gallery; private ImageButton toLeftBtn = null; private ImageButton toRightbtn = null; public GallerySlider(Context context) { super(context, null); init(context); } public GallerySlider(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public GallerySlider(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); init(context); } public void init(Context ctx){ LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE) ; inflater.inflate(R.layout.customGallery, this, true); toLeftBtn = (ImageButton) findViewById(R.id.toLeft); toLeftBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(gallery.getSelectedItemPosition() &gt; 0){ gallery.setSelection(gallery.getSelectedItemPosition()-1); } } }); toRightbtn = (ImageButton) findViewById(R.id.toRight); toRightbtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(gallery.getSelectedItemPosition() &lt; gallery.getAdapter().getCount()-1){ gallery.setSelection(gallery.getSelectedItemPosition()+1); } } }); adapter = new ArrayAdapter&lt;String&gt;(ctx, android.R.layout.simple_gallery_item, new String[] {"1","1", "1")}); gallery = (Gallery) findViewById(R.id.gallery); gallery.setBackgroundResource(R.drawable.h_sliderl); gallery.setAdapter(adapter); } @Override public void onClick(DialogInterface dialog, int which) { switch(which){ case R.id.toLeft: gallery.setSelection(gallery.getFocusedChild().getId()-1); break; case R.id.toRight: gallery.setSelection(gallery.getFocusedChild().getId()+1); break; } } public void setNewAdapter(ArrayAdapter&lt;String&gt; _adapter){ gallery.setAdapter(_adapter); ((ArrayAdapter) gallery.getAdapter()).notifyDataSetChanged (); } </code></pre> <p>}</p> <p>If I call setNewAdapter(ArrayAdapter _adapter) nothing change.. . I also tried to change the size of the gallery but it also fails(nothig happen). Is my approach false?<br> greetings marcel</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload