On orientation changed view button textview not visible Android
Try add to AndroidManifest.xml configChanges for your Activity
android:configChanges="keyboardHidden|orientation|screenSize"
android:configChanges="keyboardHidden|orientation|screenSize"
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
>
396LW NO topic_id
AD
Další témata ....(Topics)
How start certain Activity if user clicked to ListView item
Start Activity from list – launches other activities from list - latest variant!!!!
Game class Game.java game.xml
You have to add class Game to AndroidManifest.xml
Start Activity from list – launches other activities from list - latest variant!!!!
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.main);
ListView mlistView = (ListView) findViewById(R.id.idListView);
mlistView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
new String[] {"Game", "Help", "Home site"}));
mlistView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text Game, Help, Home
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
String sText = ((TextView) view).getText().toString();
Intent intent = null;
if(sText.equals("Game"))
intent = new Intent(getBaseContext(),
Game.class);
//else if(sText.equals("Help")) ..........
if(intent != null)
startActivity(intent);
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Game class Game.java game.xml
You have to add class Game to AndroidManifest.xml
<activity android:name=".Game" android:label="GameLabel">
</activity>
package cz.okhelp.listview;
import android.app.Activity;
import android.os.Bundle;
public class Game extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// you have to create game.xml
setContentView(R.layout.game);
}
}
Try this solution:
AdView adView = new AdView(getApplicationContext());//in menu inflater getActivity()
adView.setAdUnitId("ca-app-pub-87***yourNumber");
adView.setAdSize(AdSize.BANNER);
LinearLayout linLay = (LinearLayout)findViewById(R.id.idReklamaLayout);
// Add the adView to it
linLay.addView(adView);
// Initiate a generic request to load it with an ad
if(Build.MANUFACTURER.equals("unknown")) {
// Emulator
AdRequest.Builder.addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB"); // to get test ads on this device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB") // Emulator id you will get in the LogCat verbose
.build();
adView.loadAd(adRequest);
/* */
}else {
// Not Emulator
// Initiate a generic request to load it with an ad
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);/**/
}
Spinner in Android application is equivalent of ComboBox in WinApi.
Spinner get selected item to string example.
Spinner get selected item position to int example.
Main activity class MainComboBox.java
File MyOnItemSelectedListener.java
strings.xml
main.xml
Spinner get selected item to string example.
Spinner get selected item position to int example.
Main activity class MainComboBox.java
public class MainComboBox extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.countries_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
Button myButton =(Button)findViewById(R.id.button1);
myButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Spinner sp = (Spinner)findViewById(R.id.spinner);
String spinnerString = null;
spinnerString = sp.getSelectedItem().toString();
int nPos = sp.getSelectedItemPosition();
Toast.makeText(getApplicationContext(), "getSelectedItem=" + spinnerString,
Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "getSelectedItemPosition=" + nPos,
Toast.LENGTH_LONG).show();
}
});
}
}
File MyOnItemSelectedListener.java
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(), "Item is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
strings.xml
<resources>
<string name="hello">Hello World, MainComboBox!</string>
<string name="app_name">ComboBox</string>
<string name="prompt">Choose a country</string>
<string-array name="countries_array">
<item>China</item>
<item>India</item>
<item>USA</item>
<item>Indonesia</item>
<item>Brazil</item>
<item>Pakistan</item>
<item>Nigeria</item>
<item>Bangladesh</item>
<item>Russia</item>
</string-array>
</resources>
main.xml
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/prompt"
/>
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/prompt"
/>
<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
MainActivity.java
activity_main.xml
AndroidManifest.xml do not forget INTERNET uses-permission !!!!!!!
package com.asynctaskexample;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView textView;
private ProgressBar progressBar;
private DownloadWebPageTask mTask = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.TextView01);
downloadPage();
}
// AsyncTask <TypeOfVarArgParams , ProgressValue , ResultValue> .
private class DownloadWebPageTask extends AsyncTask<String, Integer, String> {
@Override
protected void onPreExecute() {
//textView.setText("Hello !!!");
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
progressBar.setVisibility(View.VISIBLE);
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
@Override
protected String doInBackground(String... urls) {
String response = "";
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(
content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
@Override
protected void onPostExecute(String result) {
progressBar.setVisibility(View.INVISIBLE);
textView.setText(result);
}
}
private void downloadPage() {
if (mTask != null
&& mTask.getStatus() != DownloadWebPageTask.Status.FINISHED) {
mTask.cancel(true);
}
// execute(String[]) you can put array of links to web pages, or array of Integer[]
// if first param is Integer[] etc.
mTask = (DownloadWebPageTask) new DownloadWebPageTask()
.execute(new String[] { "//android.okhelp.cz/android-market.html",
"//android.okhelp.cz/android-market.html" });
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mTask != null
&& mTask.getStatus() != DownloadWebPageTask.Status.FINISHED) {
mTask.cancel(true);
mTask = null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.xml
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
AndroidManifest.xml do not forget INTERNET uses-permission !!!!!!!
<uses-permission android:name="android.permission.INTERNET" />
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
//drawARGB (int a, int r, int g, int b)
// a alpha component (0..255) of the color to draw onto the canvas
// r red component (0..255)
// g green component (0..255)
// b blue component (0..255)
canvas.drawARGB(255, 0, 255, 10);
}
}
}
Editace: 2013-11-10 20:31:20
Počet článků v kategorii: 396
Url:on-orientation-changed-view-button-textview-not-visible-android