How to use commonsware with regular activity - android

I have an already established activity that must extend another activity so I'd much rather use commonsware drag and drop TouchListView class with my existing activity rather than extend ListActivity. However, I can't find an example of how to do this. In my activity's xml I have included:
<com.test.dragdrop.TouchListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tlv="http://schemas.android.com/apk/res/com.test.activities"
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
tlv:normal_height="64dip"
tlv:expanded_height="128dip"
tlv:grabber="#+id/icon"
tlv:remove_mode="slideRight"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="#id/menu_bar_top_include"
android:layout_above="#id/footerbar_lists"
android:cacheColorHint="#0000"
android:paddingTop="2dip"/>
Now, I'm not sure how translate this to creating it dynamically in my actvities code . I assume I have to place the code in onCreate() and create a RelativeLayout wrapper and put the TouchListView class inside of it, but again I'm not sure when it comes to a custom view class... any one do this before?
Note: I also tried to simply use :
TouchListView tlv = (TouchListView) findViewById(R.id.list);
but I get compiler errors:
--- for some reason the compiler cannot find "R.id.list" --- Is this because its inside a custom view? Is there some other way this needs to be specified?

There is nothing different about using TouchListView in a regular Activity than using ListView in a regular Activity. All you do is call findViewById() to get the ListView and call setAdapter() on the ListView to associate your desired ListAdapter with it.

Related

ListView in activity with other widgets

I'm building an app which I'd like to add a ListView to an activity not a listActivity but the activity also contains other widget controls. Iv tried doing it but it doesn't look good at all. Here is the xml that created the ListView in my activity:
<ListView
android:id="#+id/experienceList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="18dp"
android:layout_marginLeft="18dp" >
</ListView>
Unfortunately stackoverflow didn't allow me to post a image. But the ListView doesn't reveal all its contents. how can I make the ListView reveal all and just stretch it out, the root of the activity is a scrollView so it should probably work the way i want it.
Putting a scrollable (ListView) inside another one (ScrollView) will not work, for obvious reasons. Please refer to this question for more details, answered by Google's very own Romain Guy. Replace your ListView by a LinearLayout ...

How to make the custom xml layout for this android project?

I am trying make application from this project: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html
But here, there is a Layout that generating dynamicly. I want to create my own layout in xml file. So what should i have to do for it.
Please anyone can help me to make the xml layout from this dynamic layout ??
Thanks.
That example is not creating a "dynamic layout". The layout, which is the part you'd be defining in XML, consists of only one View object, MyView.
What I assume you are referring to by "dynamic layout" is the MyView class, which is a custom View object which accepts touch input and draws on the screen. This cannot be defined in XML... you must write the Java code to handle the logic necessary, since the regular View class (which MyView is extending) does not support such functionality.
What you would need to do is create a Java file defining the MyView class. Say for example, com.example.MyView. Then, in XML, you can include this custom view in your layout by referring to the full name, including the package name. For example...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<com.example.MyView>
android:layout_height="fill_parent"
android:layout_width="fill_parent"
</com.example.MyView>
</LinearLayout>
You can use this layout in an activity as usual using setContentView.

Android: fixed button in each view

Is there a way to make a button fix in the whole application views? I mean instead of adding the button to every xml file and code it.
Thank you.
You can keep your button xml code a different xml file. And to every other activity xml layout you can use the xml tag include like
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
<include layout="#layout/okcancelbar_button"/>
</LinearLayout>
Or like jack said, create a base activity that creates the buttons and the rest of the activities can extend from it.
you can create a custom activity in which you create one time button and every activity you will call, extended to your custom activity will have that button

TextView and ListView in a LinearLayout

I searched for similar questions but didn't get the proper answer, so posting it as a new question.
Can a LinearLayout have two TextViews and one list view? I learn that listview can be used to display array elements only if the class extends ListActivity. The Class in my app extends Activity and uses listView.
I am trying to build an RSS Reader based on IBM tutorial. On running the project I am getting parsed text in both the Text views but ListView is not displaying. I can post the code and Logcat if required.
Linear Layout can have any number of children.
ListActivity is an Activity that Android have added for convenience when dealing with activities comprised of list.
You can use ListView on a regular Activity and just implement an adapter that will populate the list items with data from your model.
Android has some ready-made adapters that can be used for simple use-cases.
of course if you need a more complicated beahviour you can extend them.
Have a look on BaseAdapter, ArrayAdapter and CursorAdapter to get a better understanding of how to use adapters.
You can have a ListView in any activity, using a ListActivity just makes your life easier (usually). See here for details.
You can have a Linear layout with different views and list view inside for example:
?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"
android:background="#drawable/background_new_search_activity_1">
<TextView
android:id="#+id/list_item_amount_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"/>
</LinearLayout>
And yes you can use the ListViewin all the activities, it is not necessary to extend ListActivity
Make sure the orientation of the ListView is set to vertical. Otherwise, it will try to display all items side by side, and those that fall outside the available view area won't be visible.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"> <!-- << orientation setting here -->

Sharing data with custom canvas view

I'm a beginner at android programming, so excuse me if my wording is slightly incorrect.
I have a custom canvas view along with a TextView inside a linear layout, defined in the layout file as
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/blah"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:gravity="top|center_horizontal"
/>
<com.*.Overlay android:id="#+id/combined"
android:layout_width="fill_parent"
android:layout_height="100dp"
/>
</LinearLayout>
I need to be able to read the text contained in the TextView from within the Overlay custom class that I created.
(The overlay class takes in 2 bitmaps and puts one on top of the other. The bitmaps used will depend on the text in the TextView.)
I considered using intents, but the Overlay class doesn't have an onCreate method.. All my code is within the onDraw method. I also added the necessary constructors.
I'm not sure what to try next, perhaps try accessing the parent linearlayout and then its child textview?
Hope I managed to explain everything in a non-confusing manner
Ok, managed to fix the issue... sort of
I found out that Views need to be contained in Activities.. so I created a new Activity with my custom view as an inner class, passed an intent with the necessary data to the activity and was able to use it successfully in my custom canvas view.
I was a bit surprised I didn't get any responses, but I guess that's because I'm new here

Categories

Resources