I went to the main.xml to the Graphical Layout and dragged over to the designer a ExpandableList . I can see it also in the main.xml runtime code:
<ExpandableListView
android:id="@+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ExpandableListView>
But when im running my application i dont see it in the android device. What i want to do is to add arrayList string to this ListView so i can select from this list in my device.
package com.testotspeech;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
public class AndroidTestToSpeechActivity extends Activity implements
TextToSpeech.OnInitListener {
/** Called when the activity is first created. */
private TextToSpeech tts;
private Button btnSpeak;
private EditText txtText;
private ListView lview;
private ArrayList<String> itemsList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
itemsList = new ArrayList<String>();
Log.i("----------",Arrays.toString(Locale.getAvailableLocales()));
itemsList.add(Arrays.toString(Locale.getAvailableLocales()));
tts = new TextToSpeech(this, this);
btnSpeak = (Button) findViewById(R.id.btnSpeak);
lview = (ListView) findViewById(R.id.expandableListView1);
txtText = (EditText) findViewById(R.id.txtText);
// button on click event
btnSpeak.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
speakOut();
}
});
}
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.ENGLISH);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
btnSpeak.setEnabled(true);
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut() {
String text = txtText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
I have a Log.i and then under it ihave itemsList wich is ArrayList Im getting a list of available languages in my Device. I want to add this list to the ListView so i can select from there the language in my device and it will change the language in real time.
The problem is that i dont see the ListView at all when running the application on my device and second problem is how to add the list to the ListView ?
Thanks.