ale jakich dw贸ch ? bo ja w sumie mam 3 activity 馃檪 Wiec narazie napisze tylko opis co to ma wykonywa膰: gdy w艂acze aplikacje pokazuj膮 mi sie przyciski takie jak: dodaj, usun, wyjscie i kilka przycisk贸w z liczbami (od 1 do 4). po kliknieciu na dodaj pojawiaja mi sie 3 EditText, w kt贸rych podaje liczbe przycisku (w kt贸rym ma zmienic nazwe i dodac adres strony, kt贸ry tez zaraz podaje ) i podaje tez adres strony i nazwe pod jaka ma sie pokazywac ten przycisk, i klikam przycisk dodaj. w tym momecie do g艂ownego ekranu ma mi wys艂a膰 zmienne (podejrzewam ze tu jest b艂ad gdzie艣 ). i do konkretnego przycisku przypisac adres strony i zmienic jego nazwe na podana ekran wczesniej. w momencie gdy klikne w przycisk otwiera mi sie przegladarka z podana strona. jest jeszcze przycisk wyjscie, w kt贸rym pojawia mi sie kolejny EditText, w kt贸rym podaje numer przycisku kt贸ry ma zosta膰 usuni臋ty, np jezeli wprowadze 2 to jego nazwa zmienia sie na sama literke 2 a adres strony zostaje wyczyszczony. a przycisku wyjscie nie musze chyba opisywa膰 馃槈
kod pierwszego ekranu :
package com.example.projekt;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
Button a, a1, a2, a3,a4, b, c, d;
String adres , nazwa, adres_str, adres_str1, adres_str2, adres_str3;
int id, usun;
Bundle e;
Intent i;
public void ObslugaKlikniec (View a){ //dodaj
i= new Intent (this, Dodaj.class);
startActivityForResult(i,2);
}
public void ObslugaKlikniec1 (View d){ //usun
Intent w= new Intent (this, Usun.class);
startActivityForResult(w,3);
}
public void ObslugaKlikniec2 (View g){ // wyjscie - nie dzia艂a...
System.exit(0);
}
public void ObslugaKlikniec3 (View j){ //str int
Uri k = Uri.parse(adres_str);
Intent l= new Intent (Intent.ACTION_VIEW,k);
startActivity (l);
}
public void ObslugaKlikniec4 (View m){ //str int
Uri n=Uri.parse(adres_str1);
Intent o= new Intent (Intent.ACTION_VIEW,n);
startActivity (o);
}
public void ObslugaKlikniec5 (View j1){ //str int
Uri x1=Uri.parse(adres_str2);
Intent y1= new Intent (Intent.ACTION_VIEW,x1);
startActivity (y1);
}
public void ObslugaKlikniec6 (View j2){ //str int
Uri x2=Uri.parse(adres_str3);
Intent y2= new Intent (Intent.ACTION_VIEW,x2);
startActivity (y2);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a=(Button) findViewById ( R.id.button1);
a1=(Button) findViewById ( R.id.button4);
a2=(Button) findViewById(R.id.button5);
a3=(Button) findViewById (R.id.button6);
a4=(Button) findViewById (R.id.button7);
b=(Button) findViewById ( R.id.button2);
c=(Button) findViewById ( R.id.button3);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==2)
{
adres=data.getStringExtra("adres");
nazwa=data.getStringExtra("nazwa");
id=data.getIntExtra("id",1);
}
switch (id){
case 1:
a1.setText ("1 "+nazwa);
adres_str=("http://"+adres);
break;
case 2:
a2.setText ("2 "+nazwa);
adres_str1=("http://"+adres);
break;
case 3:
a3.setText ("3 "+nazwa);
adres_str2=("http://"+adres);
break;
case 4 :
a4.setText("4 "+nazwa);
adres_str3=("http://"+adres);
break;
}
if(requestCode==3){
e= getIntent().getExtras();
usun = e.getInt("usun");
switch (usun){
case 1:
a1.setText ("1");
adres_str ="";
break;
case 2:
a2.setText ("2");
adres_str1 ="";
break;
case 3:
a3.setText ("3");
adres_str2 ="";
break;
case 4:
a4.setText ("4");
adres_str3 ="";
break;
}
}
}
}
kod drugiego ekranu (dodaj)
package com.example.projekt;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Dodaj extends ActionBarActivity {
EditText a;
EditText b;
EditText d;
Button c;
String adres;
String nazwa;
Intent i;
int id;
public void ObslugaKlikniecia (View v){
i= new Intent ();
adres=b.getText()+"";
id = a.getId();
nazwa= d.getText()+"";
i.putExtra ("adres", adres);
i.putExtra("id", id);
i.putExtra ("nazwa", nazwa);
setResult(2,i);
finish();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dodaj);
a=(EditText) findViewById(R.id.editText1);
b=(EditText) findViewById (R.id.editText2);
c=(Button) findViewById ( R.id.button1);
d=(EditText)findViewById (R.id.editText3);
a.setHint ("Podaj numer przycisku");
b.setHint("Podaj adres strony internetowej");
d.setHint ("Podaj nazwe pod jaka chcesz miec adres strony");
}
}
kod trzeciego ekran - usun
package com.example.projekt;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.content.Intent;
import android.os.Bundle;
public class Usun extends ActionBarActivity {
Button busun;
EditText liczba;
int usun;
Intent i;
public void ObslugaKlikniecia (View v){
usun=liczba.getId();
i= new Intent();
i.putExtra("usun", usun);
setResult(3,i);
finish();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usun);
busun=(Button) findViewById (R.id.button1);
liczba=(EditText) findViewById (R.id.editText1);
liczba.setHint("Podaj numer przycisku");
}
}