Android listview scrolling error?

Q. I'm doing an app for my school whereby I include multiple list views generated based on an SQLite table. The layout file consist of a layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button
android:id="@+id/bAddHomework"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New Homework" />
<LinearLayout
android:id="@+id/CurrentHomeworkFeed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>

</LinearLayout>

The problem is that I need the entire layout to be able to school. When I add a scroll view to the LinearLayout, then run the program and add the list views, the list views themselves become scrollable, not the entire Linear Layout... It worked in Landscape, but not portrait mode. Can you help?


HomeworkFeed = (LinearLayout) findViewById(R.id.CurrentHomeworkFeed);
// Somewhere in the code

for (int a = 0; a < records.length; a++) {
String[] splitters = records[a].split("#");
if (splitters.length > 2) {
t.add(new HomeworkListPackage(splitters[2], splitters[3], splitters[4], splitters[5], splitters[0]));
}
}
l.setAdapter(new HomeworkAdapter(this, R.layout.homeworklist, t, this));
HomeworkFeed.addView(l);

A. android:layout_width="match_parent" doesn't match for (int a = 0; a < records.length; a++) {.

(Android) How do I make an alert dialog display items in a string by position in Java?
Q. I am making an application where the user sees a list of words in a ListView, and can click on them for a translation. What I want is to see English words in the list, and the alert dialog brings up some jibberish (I will later change the jibberish into Spanish definitions).

Right now, I have both strings in order so when you click the first word in the list, the alert will contain the first word of the second set of strings. When you click on the second word in the list, I want the second word of the second string to show up in the alert. When you click on the third word in the list, I want the third word of the second string to show up in the alert. My only problem is, that the alert wont show the corresponding item from the second string. The alert is only showing the same word that was clicked on in the list.

I realize that I could make an activity for each and every word, but that seemed like a hassle, so I decided to use an alert dialog.

Can someone update my code to show me how I can make the words from the second string appear in the alert?

This is my code:

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class SpanishActivity extends ListActivity {

static final String[] basicWords = new String[] {
"Hello", "Goodbye", "Yes", "No",
"Why", "Where", "When", "What ", "Who", "How", "Absolutely", "I", "You",
"He", "She", "That", "Black", "White", "Red","Orange", "Blue", "Green",
"Yellow", "Purple", "Later" , "Now", "Today", "Tomorrow", "Left", "Right",
"Hand", "Mouth", "Tongue", "Nose", "Ear", "Eyes", "Leg", "Dog", "Cat",
"Elephant", "Snake", "Camel", "Pen", "Pencil", "Book", "Paper", "Hot",
"Cold", "Airplane", "Car", "Raining", "Sunny", "Cloudy", "Water", "Please",
"Help", "Work", "English", "America", "England", "Funny", "Thanks",
"Good", "Bad", "Happy", "Sad",
};

String[] spanishBasic = new String[]{
"afsdfb", "qerg", "nt4th", "erhn",

"ehrethn", "rth", "Kub", "ygfd ", "cvb", "ytrfvh", "jhgv", "Mvbay", "hgfv",

"gv", "cvbnhg", "gfd", "hgf", "ytr", "hgf","wthw", "wetergh", "wewrth",

"weth", "erg", "wrgwr" , "dfghj", "xdhtcjfy", "cfj", "zsrxdtcf", "oiuy",

"rxjtdcfky", "n", "dfgh", "sdfgh", "fgbh", "nkhn", "ayr", "ota", "dfgh",

"Hafghi", "ghjnp", "Ogtyh", "dfg", "fghn", "fghjnm", "ghn", "hjk",

"xdcfgh", "xcv", "hjdi", "fghish", "fghoop", "Bhjl", "bnani", "cvbn",

"Mghj", "bhjam", "hjayzi", "ghjk", "vhj", "vghj", "cfgh",

"bhj", "bhjra", "ghjshi", "fghhum",

};

/** Called when the activity is first created. */


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, basicWords));
getListView().setTextFilterEnabled(true);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);

new AlertDialog.Builder(this)
.setTitle("Spanish")
.setMessage("" + getListView().getItemAtPosition(position))
.setPositiveButton("Back to List",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}}
)
.show();


}


}

A. See the guide here: http://stackoverflow.com/questions/7811117/custom-objects-in-alertdialog-list-how-to-get-a-display-string-and-then-the-act

A Good Android Development Forum?
Q. Does anyone know of a good android development forum? I've looking for a good active community, for myself and that I can direct some students too. I can't really find a active large community.. Can anyone give me a good link?

Thanks in advance

A. You may surprise from the answer but i think stackoverflow.com is one of the best web sites in Development, it helps me alot as .NET and android developer, and contains alot of topics and questions that face developers.
Another websites i recommend is codeproject.com cause it has good examples , and github.com it helps me alot in android, especially with the listview and lazy loading of data.
Finally don't forget if you have any problem in android developement just google it, and you will see hundreds of good answers most of them from stackoverflow.com of course :)
hope this helps




Powered by Yahoo! Answers

No comments:

Post a Comment