Note that there are some explanatory texts on larger screens.

plurals
  1. POcustom scrollview not appearing
    text
    copied!<p>I have a custom ScrollView that works fine if it is the only thing in the emulator. </p> <p>For example, this works fine:</p> <pre><code> public class Timeline2Activity extends Activity { private TimelineView tlv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tlv = new TimelineView(this); setContentView(tlv); } } </code></pre> <p>But if I first add widgets then it fails to appear. I've searched and experimented for 2 days and nothing works. </p> <p>Here is the class declaration of the custom ScrollView:</p> <pre><code>public class TimelineView extends ScrollView implements OnTouchListener { </code></pre> <p>And here are the constructors:</p> <pre><code>public TimelineView(Context context) { super(context); this.setOnTouchListener(this); setVisibility(VISIBLE); } //the following constructor is needed to inflate the view from XML public TimelineView(Context context, AttributeSet ats) { super(context,ats); this.setOnTouchListener(this); setVisibility(VISIBLE); } </code></pre> <p>Here is the main.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" &gt; &lt;Button android:id="@+id/zoomall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Zoom All" /&gt; &lt;Button android:id="@+id/zoomout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" /&gt; &lt;Button android:id="@+id/zoomin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+" /&gt; &lt;Spinner android:id="@+id/category_spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:prompt="@string/category_prompt" /&gt; &lt;/LinearLayout&gt; &lt;com.projects.timeline2.TimelineView android:id="@+id/timeline_view" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>And here is the main program:</p> <pre><code>public class Timeline2Activity extends Activity { private TimelineView tlv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //tlv = new TimelineView(this); //setContentView(tlv); setContentView(R.layout.main); Spinner spinnerCategory = (Spinner) findViewById(R.id.category_spinner); ArrayAdapter&lt;CharSequence&gt; adapterCategory = ArrayAdapter.createFromResource( this, R.array.categories, android.R.layout.simple_spinner_item); adapterCategory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerCategory.setAdapter(adapterCategory); spinnerCategory.setOnItemSelectedListener(new MyOnItemSelectedListener()); //TimelineView tlv = (TimelineView) findViewById(R.id.timeline_view); //ViewGroup container = (ViewGroup) findViewById(R.id.container); //container.addView(tlv); } public class MyOnItemSelectedListener implements OnItemSelectedListener { public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id) { Toast.makeText(parent.getContext(), "The selection is " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); } public void onNothingSelected(AdapterView parent) { // Do nothing. } } } </code></pre> <p>The lines commented out are stuff I've tried but didn't work either.</p> <p>This code correctly puts 3 buttons and a spinner in a horizontal row across the top. But TimelineView fails to appear below them. I know that TimelineView is running because I can see debugging output in the LogCat that I put in.</p> <p>I'm at my wits end and hope someone can shed some light. This seems like a common fundamental need and sure deserves a google tutorial.</p>
 

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