blackeyes972
12-01-2013, 14:07
Salve spero sia l'area giusta dove postare, mi sto' avvicinando alla programmazione android sono veramente digiuno. Per farlo uso l'adt e ho visto un paio di video tutorial su youtube. Volevo creare una semplice applicazione composta da tre bottoni:
Sito web: cliccandolo dovrebbe semplicemente rimandare ad un indirizzo preimpostato
Feed Rss: cliccandolo dovrebbe aprire un file di feed prevalentemente generato da wordpress (all'interno dell'applicazione)
About dove riportare semplicemente delle note relative all'applicazione.
Ora creare il layout è abbastanza intuitivo e piuttosto semplice,
Ho creato l'interfaccia grafica :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
* * xmlns:tools="http://schemas.android.com/tools"
* * android:layout_width="match_parent"
* * android:layout_height="match_parent"
* * tools:context=".MainActivity" >
* * <Button
* * * * android:id="@+id/button1"
* * * * android:layout_width="wrap_content"
* * * * android:layout_height="wrap_content"
* * * * android:layout_alignParentTop="true"
* * * * android:layout_centerHorizontal="true"
* * * * android:layout_marginRight="14dp"
* * * * android:layout_marginTop="35dp"
* * * * android:text="@string/sito_web" />
* * <Button
* * * * android:id="@+id/button2"
* * * * android:layout_width="wrap_content"
* * * * android:layout_height="wrap_content"
* * * * android:layout_alignLeft="@+id/button1"
* * * * android:layout_below="@+id/button1"
* * * * android:layout_marginTop="43dp"
* * * * android:text="@string/Feed_Rss" />
* * <Button
* * * * android:id="@+id/button3"
* * * * android:layout_width="wrap_content"
* * * * android:layout_height="wrap_content"
* * * * android:layout_alignLeft="@+id/button2"
* * * * android:layout_below="@+id/button2"
* * * * android:layout_marginTop="73dp"
* * * * android:text="@string/About" />
* *
</RelativeLayout>
e ho cominciato a scrivere qualche riga di codice
package com.example.alex;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button button1, button2, button3;
* * @Override
* * protected void onCreate(Bundle savedInstanceState) {
* * * * super.onCreate(savedInstanceState);
* * * * setContentView(R.layout.activity_main);
* * * * button1 = (Button) findViewById (R.id.button1);
* * * * button2 = (Button) findViewById (R.id.button2);
* * * * button3 = (Button) findViewById (R.id.button3);
* * * * button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
* * * * button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
* * * * button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
* * }
* * @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;
* * }
* *
}
dove ho dichiarato le tre variabili button, poi ho usato il findViewById per fare in modo che quando clicco su un bottone android "sappia" che ho premuto proprio quello ed infine ho creato un listner dove dovro' scrivere quello che vorrei far succedere quando clicco su un bottone.
non riesco pero' ad assegnare ai pulsanti le azioni da effettuare quando vengono premuti.
Sito web: cliccandolo dovrebbe semplicemente rimandare ad un indirizzo preimpostato
Feed Rss: cliccandolo dovrebbe aprire un file di feed prevalentemente generato da wordpress (all'interno dell'applicazione)
About dove riportare semplicemente delle note relative all'applicazione.
Ora creare il layout è abbastanza intuitivo e piuttosto semplice,
Ho creato l'interfaccia grafica :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
* * xmlns:tools="http://schemas.android.com/tools"
* * android:layout_width="match_parent"
* * android:layout_height="match_parent"
* * tools:context=".MainActivity" >
* * <Button
* * * * android:id="@+id/button1"
* * * * android:layout_width="wrap_content"
* * * * android:layout_height="wrap_content"
* * * * android:layout_alignParentTop="true"
* * * * android:layout_centerHorizontal="true"
* * * * android:layout_marginRight="14dp"
* * * * android:layout_marginTop="35dp"
* * * * android:text="@string/sito_web" />
* * <Button
* * * * android:id="@+id/button2"
* * * * android:layout_width="wrap_content"
* * * * android:layout_height="wrap_content"
* * * * android:layout_alignLeft="@+id/button1"
* * * * android:layout_below="@+id/button1"
* * * * android:layout_marginTop="43dp"
* * * * android:text="@string/Feed_Rss" />
* * <Button
* * * * android:id="@+id/button3"
* * * * android:layout_width="wrap_content"
* * * * android:layout_height="wrap_content"
* * * * android:layout_alignLeft="@+id/button2"
* * * * android:layout_below="@+id/button2"
* * * * android:layout_marginTop="73dp"
* * * * android:text="@string/About" />
* *
</RelativeLayout>
e ho cominciato a scrivere qualche riga di codice
package com.example.alex;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button button1, button2, button3;
* * @Override
* * protected void onCreate(Bundle savedInstanceState) {
* * * * super.onCreate(savedInstanceState);
* * * * setContentView(R.layout.activity_main);
* * * * button1 = (Button) findViewById (R.id.button1);
* * * * button2 = (Button) findViewById (R.id.button2);
* * * * button3 = (Button) findViewById (R.id.button3);
* * * * button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
* * * * button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
* * * * button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
* * }
* * @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;
* * }
* *
}
dove ho dichiarato le tre variabili button, poi ho usato il findViewById per fare in modo che quando clicco su un bottone android "sappia" che ho premuto proprio quello ed infine ho creato un listner dove dovro' scrivere quello che vorrei far succedere quando clicco su un bottone.
non riesco pero' ad assegnare ai pulsanti le azioni da effettuare quando vengono premuti.