T
tomycat
Ambitioniertes Mitglied
- 0
hallo,
im Textview steht nur hello w. aber nicht Please wait ?!?
die Layout:
im Textview steht nur hello w. aber nicht Please wait ?!?
Code:
public class normal extends Activity implements OnClickListener{
private Button zurueck;
private Button jetztsenden;
TextView resultArea; // tut
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
resultArea= (TextView) findViewById(R.id.resultArea);
resultArea = new TextView(this); //tut
resultArea.setText("Please wait."); //tut
setContentView(resultArea); //tut
new FetchSQL().execute(); //tut
setContentView(R.layout.normal);
zurueck = (Button) findViewById(R.id._zurueck);
zurueck.setOnClickListener(this);
jetztsenden = (Button) findViewById(R.id.jetzt_senden);
jetztsenden.setOnClickListener(this);
//////////// Servereinstellungen laden...
//////// Serveradresse:
/// kommt später rein ....
///////////////
}
public void onClick(View v)
{
if (v == zurueck)
{
Intent intent = new Intent(this, MainActivity.class);
this.startActivity(intent);
}
if (v == jetztsenden)
{
/// postgressql
/// postgressql ende
Toast.makeText(getBaseContext(),
"senden war efolgreich!",
Toast.LENGTH_LONG).show();
}
}
//AB hier tut
private class FetchSQL extends AsyncTask<Void,Void,String> {
@Override
protected String doInBackground(Void... params) {
String retval = "";
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
retval = e.toString();
}
String url = "jdbc:postgresql://10.0.2.2/dbname?user=username&password=pass";
Connection conn;
try {
DriverManager.setLoginTimeout(5);
conn = DriverManager.getConnection(url);
Statement st = conn.createStatement();
String sql;
sql = "SELECT 1";
ResultSet rs = st.executeQuery(sql);
while(rs.next()) {
retval = rs.getString(1);
}
rs.close();
st.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
retval = e.toString();
}
return retval;
}
@Override
protected void onPostExecute(String value) {
resultArea.setText(value);
}
// Bis hier tut
}}
Code:
<?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" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/server_name_"
/>
<EditText
android:id="@+id/server_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/server_pass_"
/>
<EditText
android:id="@+id/server_pass"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/resultArea"
android:layout_width="100dp"
android:layout_height="20dp"
android:text="hello_world"
/>
<Button
android:id="@+id/jetzt_senden"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/jetzt_senden"
android:layout_weight="2"
/>
<Button
android:id="@+id/_zurueck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_zurueck"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>