Rady a tipy pro vyvoj ⇒ potize s vyvojem aplikace, uzivatelsky vstup
Moderátoři: mArtinko5MB, mArtinko5MB
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
potize s vyvojem aplikace, uzivatelsky vstup
Potreboval bych vytisknout vsechny binarni retezce pro zadanou promenlivou deku N a vedle nich na kazdem radku vytvorit
TextAreu kam uzivatel zada cisla napravo priklad: 0.11, 2.11, 4.60 ktera pote nactu a pouziji v aplikaci
000000000 0.11
000000001 2.12
000000010 4.60
000000011 5.34
...
111111111 9.81
Pokusil jsem se k tomu pouzit "linear layout" ale neumim v cyklu tisknout elementy
activity_main.xml.
Kdyby to bylo v souboru MainActivity.java tak snad ano, ale v .xml kde se elementy maji nachazet ne.
Takto se mi snad povedlo vytvorit jich jen konstantni pocet a to jeste pracne a nepresne v Design Editoru.
Jak to nejsnaze vyresit ?
TextAreu kam uzivatel zada cisla napravo priklad: 0.11, 2.11, 4.60 ktera pote nactu a pouziji v aplikaci
000000000 0.11
000000001 2.12
000000010 4.60
000000011 5.34
...
111111111 9.81
Pokusil jsem se k tomu pouzit "linear layout" ale neumim v cyklu tisknout elementy
activity_main.xml.
Kdyby to bylo v souboru MainActivity.java tak snad ano, ale v .xml kde se elementy maji nachazet ne.
Takto se mi snad povedlo vytvorit jich jen konstantni pocet a to jeste pracne a nepresne v Design Editoru.
Jak to nejsnaze vyresit ?
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
v xml si nadefinujes ten LinearLayout, ktery bude prazdny
a pak ve smycce volas neco jako
linearLayout.addView(new EditText(context));
+ LayoutParametry nastavit
a pak ve smycce volas neco jako
linearLayout.addView(new EditText(context));
+ LayoutParametry nastavit
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Rada se mi zda funkcni, ale nemohl bys mi sem hodit nejaky MWE, jsem uplny zacatecnik a nevim jak to cele nastavit.
Diky moc. Max
Diky moc. Max
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
tady je ukazka s vyuzitim toho LinearLayout. Ale pokud je tech hodnot (řádků) vice, tak urcite vyuzit RecyclerView (coz muzes vyuzit i tak, aspon se to naucis a je to pak hojne vyuzivane)
Tady nejaka testovaci Activity
ta vyuziva tento layout
a jednotlive řádky jsou takto
vysledek
Tady nejaka testovaci Activity
Kód: Vybrat vše
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AddToLinLayActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_view_to_lin_lay);
LinearLayout dynamicContent = findViewById(R.id.dynamic_content);
LayoutInflater inflater = LayoutInflater.from(this);
int numbers[] = {654, 213, 113, 213, 23, 45,84 };
for (int number : numbers) {
View newRow = inflater.inflate(R.layout.item_view_to_lin_lay, dynamicContent, false);
TextView binaryString = newRow.findViewById(R.id.binary_string);
binaryString.setText(Integer.toBinaryString(number));
dynamicContent.addView(newRow);
}
}
}
Kód: Vybrat vše
<?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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dynamicky vlozene řádky" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/dynamic_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
</LinearLayout>
Kód: Vybrat vše
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:id="@+id/binary_string"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
tools:text="0010100111010010101" />
<EditText
android:id="@+id/value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Diky moc za cely kod.
Ktere XMLko mam ale pouzit, to 1. ci to druhe.
I tak mi to nejde zkompilovat, sviti tam cervene ta Rka,annotation a Nullable.
Ktere XMLko mam ale pouzit, to 1. ci to druhe.
I tak mi to nejde zkompilovat, sviti tam cervene ta Rka,annotation a Nullable.
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
obe dve XML
R.layout.activity_add_view_to_lin_lay
je to prvni a
R.layout.item_view_to_lin_lay
je to druhe
annotation muzes smazat, i Nullable
R se vygeneruje az se to podari prelozit, tak to tak pak importujes svoje
R.layout.activity_add_view_to_lin_lay
je to prvni a
R.layout.item_view_to_lin_lay
je to druhe
annotation muzes smazat, i Nullable
R se vygeneruje az se to podari prelozit, tak to tak pak importujes svoje
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
To mi prave neni jasne kam je ulozim.
Jsem zvykly mit jedno xmlko pojmenovane
activity_main.xml
A jak naimportuji R?
ANdroid Studio uzivam teprve tyden.
Jsem zvykly mit jedno xmlko pojmenovane
activity_main.xml
A jak naimportuji R?
ANdroid Studio uzivam teprve tyden.
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
ve slozce, kde ted mas ulozene activity_main.xml vytvoris novy *.xml soubor s tema nazvama co jsem psal
az je tam budes mit, zkus prekopilovat, hodi to chybu s tim R a pak kdyz kliknes v kodu na to R tak by ti to melo nabidnout import
az je tam budes mit, zkus prekopilovat, hodi to chybu s tim R a pak kdyz kliknes v kodu na to R tak by ti to melo nabidnout import
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Zkusil jsem si napsat vlastni kod, ale nefunguje to, viz nize.
Chtel jsem vzdy na jednom radku
txt[1] tv[1]
...
txt[8] tv[8]
Muzes mi kod poopravit ?
Posilam .java i .xml.
KOD MAINACTIVITY.java:
package com.ebookfrenzy.motionevent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.widget.GridLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Button;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioButton button3 = findViewById(R.id.radioButton2);
button3.setText("8");
LinearLayout myLayout =
findViewById(R.id.activity_main);
myLayout.setOnTouchListener(
new ConstraintLayout.OnTouchListener() {
public boolean onTouch(View v,
MotionEvent m) {
handleTouch(m);
return true;
}
}
);
}
public void click(View view) {
Button button2 = findViewById(R.id.button2);
button2.setText("OK2");
};
public void click2(View view) {
Button button3 = findViewById(R.id.button2);
button3.setText("hello");
// Put buttons into an array
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.activity_main);
// GridLayout gridLayout=(GridLayout) findViewById(R.id.activity_main);
// Put buttons into an array
// Button[] txt = {new Button(this), new Button(this)};
Button[] txt = new Button[8];
TextView[] tv = new TextView[8];
// loop over all values of i between 0 to the end of the button array
for (int i = 0; i < txt.length; i = i + 1) {
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
// Access array elements by index so txt1 is txt[1], etc.
txt=new Button(this);
txt.setText(Integer.toBinaryString(i));
linearLayout.addView(txt);
tv=new TextView(this);
linearLayout.addView(tv);
}
};
void handleTouch(MotionEvent m)
{
// TextView textView1 = findViewById(R.id.textView1);
TextView textView2 = findViewById(R.id.textView2);
int pointerCount = m.getPointerCount();
for (int i = 0; i < pointerCount; i++)
{
int x = (int) m.getX(i);
int y = (int) m.getY(i);
int id = m.getPointerId(i);
int action = m.getActionMasked();
int actionIndex = m.getActionIndex();
String actionString;
switch (action)
{
case MotionEvent.ACTION_DOWN:
actionString = "DOWN";
break;
case MotionEvent.ACTION_UP:
actionString = "UP";
break;
case MotionEvent.ACTION_POINTER_DOWN:
actionString = "PNTR DOWN";
break;
case MotionEvent.ACTION_POINTER_UP:
actionString = "PNTR UP";
break;
case MotionEvent.ACTION_MOVE:
actionString = "MOVE";
break;
default:
actionString = "";
}
String touchStatus = "Action: " + actionString + " Index: " + actionIndex + " ID: " + id + " X: " + x + " Y: " + y+"HERE"+pointerCount+"ok";
if (id == 0)
textView2.setText(touchStatus);
//else
// textView1.setText(touchStatus);
}
}
}
KOD ACTIVITY_MAIN.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/touch_status_two"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="181dp"
android:layout_height="18dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName"
app:layout_constraintVertical_bias="0.504" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton"
tools:layout_editor_absoluteX="133dp"
tools:layout_editor_absoluteY="155dp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click2"
android:text="Button"
tools:layout_editor_absoluteX="154dp"
tools:layout_editor_absoluteY="237dp" />
<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="100dp"
tools:layout_editor_absoluteY="433dp" />
</LinearLayout>
Chtel jsem vzdy na jednom radku
txt[1] tv[1]
...
txt[8] tv[8]
Muzes mi kod poopravit ?
Posilam .java i .xml.
KOD MAINACTIVITY.java:
package com.ebookfrenzy.motionevent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.widget.GridLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Button;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioButton button3 = findViewById(R.id.radioButton2);
button3.setText("8");
LinearLayout myLayout =
findViewById(R.id.activity_main);
myLayout.setOnTouchListener(
new ConstraintLayout.OnTouchListener() {
public boolean onTouch(View v,
MotionEvent m) {
handleTouch(m);
return true;
}
}
);
}
public void click(View view) {
Button button2 = findViewById(R.id.button2);
button2.setText("OK2");
};
public void click2(View view) {
Button button3 = findViewById(R.id.button2);
button3.setText("hello");
// Put buttons into an array
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.activity_main);
// GridLayout gridLayout=(GridLayout) findViewById(R.id.activity_main);
// Put buttons into an array
// Button[] txt = {new Button(this), new Button(this)};
Button[] txt = new Button[8];
TextView[] tv = new TextView[8];
// loop over all values of i between 0 to the end of the button array
for (int i = 0; i < txt.length; i = i + 1) {
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
// Access array elements by index so txt1 is txt[1], etc.
txt=new Button(this);
txt.setText(Integer.toBinaryString(i));
linearLayout.addView(txt);
tv=new TextView(this);
linearLayout.addView(tv);
}
};
void handleTouch(MotionEvent m)
{
// TextView textView1 = findViewById(R.id.textView1);
TextView textView2 = findViewById(R.id.textView2);
int pointerCount = m.getPointerCount();
for (int i = 0; i < pointerCount; i++)
{
int x = (int) m.getX(i);
int y = (int) m.getY(i);
int id = m.getPointerId(i);
int action = m.getActionMasked();
int actionIndex = m.getActionIndex();
String actionString;
switch (action)
{
case MotionEvent.ACTION_DOWN:
actionString = "DOWN";
break;
case MotionEvent.ACTION_UP:
actionString = "UP";
break;
case MotionEvent.ACTION_POINTER_DOWN:
actionString = "PNTR DOWN";
break;
case MotionEvent.ACTION_POINTER_UP:
actionString = "PNTR UP";
break;
case MotionEvent.ACTION_MOVE:
actionString = "MOVE";
break;
default:
actionString = "";
}
String touchStatus = "Action: " + actionString + " Index: " + actionIndex + " ID: " + id + " X: " + x + " Y: " + y+"HERE"+pointerCount+"ok";
if (id == 0)
textView2.setText(touchStatus);
//else
// textView1.setText(touchStatus);
}
}
}
KOD ACTIVITY_MAIN.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/touch_status_two"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="181dp"
android:layout_height="18dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName"
app:layout_constraintVertical_bias="0.504" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton"
tools:layout_editor_absoluteX="133dp"
tools:layout_editor_absoluteY="155dp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click2"
android:text="Button"
tools:layout_editor_absoluteX="154dp"
tools:layout_editor_absoluteY="237dp" />
<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="100dp"
tools:layout_editor_absoluteY="433dp" />
</LinearLayout>
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
hmm tak treba neco takoveho?
MainActivity
activity_main.xml
MainActivity
Kód: Vybrat vše
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_max2);
RadioButton button3 = findViewById(R.id.radioButton2);
button3.setText("8");
LinearLayout myLayout = findViewById(R.id.activity_main);
myLayout.setOnTouchListener(
new ConstraintLayout.OnTouchListener() {
public boolean onTouch(View v, MotionEvent m) {
handleTouch(m);
return true;
}
}
);
}
public void click(View view) {
Button button2 = findViewById(R.id.button2);
button2.setText("OK2");
}
public void click2(View view) {
Button button3 = findViewById(R.id.button2);
button3.setText("hello");
// Put buttons into an array
LinearLayout holder = (LinearLayout) findViewById(R.id.holder);
// GridLayout gridLayout=(GridLayout) findViewById(R.id.activity_main);
// Put buttons into an array
// Button[] txt = {new Button(this), new Button(this)};
Button[] txt = new Button[8];
TextView[] tv = new TextView[8];
// loop over all values of i between 0 to the end of the button array
for (int i = 0; i < txt.length; i = i + 1) {
LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.HORIZONTAL);
// Access array elements by index so txt1 is txt[1], etc.
txt[i] = new Button(this);
txt[i].setText(Integer.toBinaryString(i));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
row.addView(txt[i], params);
tv[i] = new TextView(this);
tv[i].setText("tv, index "+i);
row.addView(tv[i], params);
holder.addView(row);
}
}
void handleTouch(MotionEvent m) {
// TextView textView1 = findViewById(R.id.textView1);
TextView textView2 = findViewById(R.id.textView2);
int pointerCount = m.getPointerCount();
for (int i = 0; i < pointerCount; i++) {
int x = (int) m.getX(i);
int y = (int) m.getY(i);
int id = m.getPointerId(i);
int action = m.getActionMasked();
int actionIndex = m.getActionIndex();
String actionString;
switch (action) {
case MotionEvent.ACTION_DOWN:
actionString = "DOWN";
break;
case MotionEvent.ACTION_UP:
actionString = "UP";
break;
case MotionEvent.ACTION_POINTER_DOWN:
actionString = "PNTR DOWN";
break;
case MotionEvent.ACTION_POINTER_UP:
actionString = "PNTR UP";
break;
case MotionEvent.ACTION_MOVE:
actionString = "MOVE";
break;
default:
actionString = "";
}
String touchStatus = "Action: " + actionString + " Index: " + actionIndex + " ID: " + id + " X: " + x + " Y: " + y + "HERE" + pointerCount + "ok";
if (id == 0)
textView2.setText(touchStatus);
//else
// textView1.setText(touchStatus);
}
}
}
Kód: Vybrat vše
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Touch status Two"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="181dp"
android:layout_height="18dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName"
app:layout_constraintVertical_bias="0.504" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton"
tools:layout_editor_absoluteX="133dp"
tools:layout_editor_absoluteY="155dp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click2"
android:text="Button"
tools:layout_editor_absoluteX="154dp"
tools:layout_editor_absoluteY="237dp" />
<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="100dp"
tools:layout_editor_absoluteY="433dp" />
<LinearLayout
android:id="@+id/holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</LinearLayout>
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Vyborne, uz jsem s tim pokrocil i sam, ale mam dalsi problem :
potrebuji precist do kodu data z tech dynamicky vytvorenych radku po stisknuti jednoho buttonu (button4).
Davam sem `.xml` i `MainActivity.java`, ktere bych rad upravil.
Nevim kam napsat `editText`. Kdyz ho napisi do funkce definovane mimo click2() tak nema pristup k datum funkce click2()
a kdyz ho napisi do ni, tak nebude reagovat na sve jmeno v activity_main.xml.
A zde je XML
potrebuji precist do kodu data z tech dynamicky vytvorenych radku po stisknuti jednoho buttonu (button4).
Davam sem `.xml` i `MainActivity.java`, ktere bych rad upravil.
Nevim kam napsat `editText`. Kdyz ho napisi do funkce definovane mimo click2() tak nema pristup k datum funkce click2()
a kdyz ho napisi do ni, tak nebude reagovat na sve jmeno v activity_main.xml.
Kód: Vybrat vše
public void click(View view) {
String col1;
String col2;
TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
TableRow row = new TableRow(this);
TextView tv = new TextView(this);
TextView c = new TextView(this);
EditText etUserInfoNewValue = (EditText)findViewById(R.id.simpleEditText);
tv.setText("This is text");
tl.addView(row);
row.addView(tv);
for (int x = 0; x < 5; x++) {
col1 = "(" + x + ")"+Integer.toBinaryString(x);
col2 = "1";
TableRow newRow = new TableRow(this);
TextView column1 = new TextView(this);
TextView column2 = new TextView(this);
EditText editText1 = new EditText(this);
TextView column3 = new TextView(this);
column1.setText(col1);
column1.setText(col1);
column2.setText(col2);
newRow.addView(column1);
newRow.addView(editText1);
newRow.addView(column3);
tl.addView(newRow, new TableLayout.LayoutParams());
}
}
A zde je XML
Kód: Vybrat vše
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android2="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout android:layout_width="fill_parent"
android:id="@+id/tableLayout1" android:layout_height="wrap_content">
</TableLayout>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="click2"/>
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android2:inputType="numberDecimal"
android:hint="Enter Your Name Here" />
<Button
android2:id="@+id/button4"
android2:layout_width="wrap_content"
android:layout_width="match_parent"
android2:layout_height="wrap_content"
android2:text="Button"
android:onClick="click4"/>
</LinearLayout>
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
kod co si sem dal neni cely, tak tezko z toho zkouset, ale obecne udelas neco jako
Kód: Vybrat vše
// toto presunout, at to jsou promene v MainActivity, jinak to byly jen lokalni promene
Button[] txt = new Button[8];
TextView[] tv = new TextView[8];
// a pak treba v tom kliku
for (int i = 0; i < txt.length; i = i + 1) {
String value = tv[i].getText().toString();
Log.d("App", "Value = "+value);
}
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup/chyba v aplikaci
Nemohu nalezt chybu v nasledujicim zadani aplikace:
mame mnozinu hracu {1,...,n} a vyherni funkci z mnoziny vsech podmnozin do {0,1}.
Aplikace ma nacist vstupy ve tvaru binarnich retezcu delky n ,kazdy odpovida jedne koalici S,
a vypocitat kolik mnozin S ma vlastnost, ze v(S)=1 a v(S-{i})=0 pro kazdeho hrace i.
Kod jsem napsal ale je tam nekde zaludna chyba protoze napriklad
00=v({0,0})=0
01=v({0,1})=0
10=v({1,0})=0
11=v({1,1})=1
haze vysledek 0 namisto 1 (zastoupeno mnozinou {1,1}). Mnozin vsech takovych S pro vsechny hrace i dohromady maji velikost takovou, cemu v kodu rikam "swingove".
Melo by tedy byt swingove=1, ale dava mi to swingove=0. Nize prikladam MainActivity.java i aktivyty_Main.xml.
Doufam, ze nekdo poradi, fakt to nemohu najit.
Abych upresnil jak aplikace funguje, tak kliknutim na button4 po jedne zvysuji kolik ma byt vsech S,
kliknutim na button2 vygeneruji vstup a button5 vypocita dva vystupy, shap, ktery nas ted nezjima a banzhaf
ktery ma po retezci "K" vytisknout cislo swingove.
Kteroukoliv cats programu na pozadani vysvetlim.
XML FILE
mame mnozinu hracu {1,...,n} a vyherni funkci z mnoziny vsech podmnozin do {0,1}.
Aplikace ma nacist vstupy ve tvaru binarnich retezcu delky n ,kazdy odpovida jedne koalici S,
a vypocitat kolik mnozin S ma vlastnost, ze v(S)=1 a v(S-{i})=0 pro kazdeho hrace i.
Kod jsem napsal ale je tam nekde zaludna chyba protoze napriklad
00=v({0,0})=0
01=v({0,1})=0
10=v({1,0})=0
11=v({1,1})=1
haze vysledek 0 namisto 1 (zastoupeno mnozinou {1,1}). Mnozin vsech takovych S pro vsechny hrace i dohromady maji velikost takovou, cemu v kodu rikam "swingove".
Melo by tedy byt swingove=1, ale dava mi to swingove=0. Nize prikladam MainActivity.java i aktivyty_Main.xml.
Doufam, ze nekdo poradi, fakt to nemohu najit.
Abych upresnil jak aplikace funguje, tak kliknutim na button4 po jedne zvysuji kolik ma byt vsech S,
kliknutim na button2 vygeneruji vstup a button5 vypocita dva vystupy, shap, ktery nas ted nezjima a banzhaf
ktery ma po retezci "K" vytisknout cislo swingove.
Kteroukoliv cats programu na pozadani vysvetlim.
Kód: Vybrat vše
package com.example.tablelayout6;
import androidx.appcompat.app.AppCompatActivity;
import android.icu.text.MeasureFormat;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TableRow;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.TableLayout;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import java.lang.StringBuilder;
public class MainActivity extends AppCompatActivity {
public Integer N=0;
public String a="2";
private EditText editText1;
private EditText linear;
private Integer[] hodnoty =new Integer[10];
private String[] koal=new String[10];
private float[] shap=new float[10];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean iswinning(Integer J,int ii) {
return true;
}
public Integer fact (Integer f) {
if (f==0) return 1;
else return f*fact((Integer) (f-1));
}
//T pocetHracu
public Integer[] stringToArray(String binary) {
Integer[] arrayOfPLayers=new Integer[binary.length()];
for(int i=0;i<binary.length();i++) {
arrayOfPLayers[i]=Integer.parseInt("" + binary.charAt(i));
}
return arrayOfPLayers;
}
//N je pocet koalici
public void click5(View view) {
int pocetHracu=Integer.toBinaryString(N-1).length();
Integer[][] koalice=new Integer[N][pocetHracu];
Integer[][] koalice2=new Integer[N][pocetHracu];
Integer[][] koalice3=new Integer[N][pocetHracu];
TextView tv6 = (TextView) findViewById(R.id.textView6);
for (Integer ith=0;ith<N;ith++) {
for(Integer T=0;T<pocetHracu;T++) {
String StringPadded=stf(Integer.toBinaryString(ith),pocetHracu-Integer.toBinaryString(ith).length());
koalice[ith][T]=stringToArray(StringPadded)[T];
koalice2[ith][T]=stringToArray(StringPadded)[T];
koalice3[ith][T]=stringToArray(StringPadded)[T];
}
}
float[] shap=new float[pocetHracu];
float[] vyhryKoalici = new float[N];
Integer[] isSwing=new Integer[pocetHracu];
for (int i=0; i<N;i++) {
editText1 = (EditText) findViewById(330+i);
String a=editText1.getText().toString();
float f1 = Float.parseFloat(a);
vyhryKoalici[i]=f1;
}
Integer[] kolikJeSwingu= new Integer[pocetHracu];
String S="";
Integer jth;
for (int p = 0; p < pocetHracu; p++) {
isSwing[p] =0;
kolikJeSwingu[p]=0;
}
for(Integer T=0;T<pocetHracu;T++) {
for (Integer ith = 0; ith < N; ith++) {
int bool = 1;
//vyhryKoalici[ith];
//musis najit jth<N pro ktere koalice3[jth]=S-ith
if (koalice[ith][T] == 1 && vyhryKoalici[ith]==1) {
koalice3[ith][T] = 0;
for (jth = 0; jth < N; jth++) {
for (int k = 0; k < pocetHracu; k++) {
if (k != T && koalice[ith][k] != koalice3[jth][k]) {
bool = 0;
}
}
if (vyhryKoalici[jth] == 0 && bool == 1) {
isSwing[T]++;
}
}
koalice3[ith][T]=1;
}
}
}
//kolikJeSwingu(Integer TmaSwing, Integer pocetHracu, Integer pocetKoalici,
// Integer[][] koal, Integer[] koalicePriKtereJeSwing, float[] vyhryKoal)
for (Integer ith = 0; ith < N; ith++) {
for(Integer T=0;T<pocetHracu;T++) {
//isSwingBool(Integer kteraKoalice, Integer TmaSwing, Integer pocetHracu, Integer pocetKoalici,
// Integer[][] koal, Integer[] koalicePriKtereJeSwing, float[] vyhryKoal) {
// kolikJeSwingu[T]+=kolikJeSwingu(T, pocetHracu, N,
// koalice, koalice[ith],vyhryKoalici);
if (koalice[ith][T] == 1) {
koalice2[ith][T] = 0;
for (jth = 0; jth < N; jth++) {
int bool = 1;
for (int k = 0; k < pocetHracu; k++) {
if (k != T && koalice[ith][k] != koalice2[jth][k]) {
bool = 0;
}
}
int bool2=0;
koalice2[ith][T] = 1;
if (vyhryKoalici[ith] == 1 && vyhryKoalici[jth] == 0) {
for (int k = 0; k < pocetHracu; k++) {
if (koalice[ith][k] != koalice2[jth][k]) {
bool2++;
}
}
// if(bool2==1) {
// isSwing[T]++;
// }
}
koalice2[ith][T] = 1;
Integer t = 0;
for (int p = 0; p < pocetHracu; p++) {
t += koalice[ith][p];
}
// Integer[] isSwing=new Integer[pocetHracu];
if (bool == 1) {
shap[T] += (float) ((float) fact(t - 1) * fact(pocetHracu - t) / (float) (fact(pocetHracu)) * (float) (vyhryKoalici[ith] - vyhryKoalici[jth]));
}
}
}
}
}
S+="here";
String T2="";
T2+="banzhaf";
Integer swingove=0;
for(int p=0;p<pocetHracu;p++) {
swingove+=isSwing[p];
}
String strPokus="banzhaf ";
float[] banzh=new float[pocetHracu];
for(int p=0;p<pocetHracu;p++)
{
banzh[p]=(float) isSwing[p]/(float) swingove;
}
String strPokus2="shap ";
for(int i=0;i<pocetHracu;i++) {
// S+=(" "+String.valueOf(shap[i]));
strPokus2+=String.format("%.2f ",shap[i]);
strPokus+=String.format("%.2f ",banzh[i]);
}
// tv6.setText(strPokus2+"\n"+strPokus+"\nswing"+isSwing[0]+"swingPrvni:"+isSwing[1]+"\nH"+swingove);
tv6.setText(strPokus2+"\n"+strPokus+"K"+String.valueOf(swingove));
}
public void click4(View view) {
//
linear = (EditText) findViewById(R.id.simpleEditText);
if(N==0) {
linear.setText("0");
}
String a = linear.getText().toString();
N = Integer.parseInt(a);
N++;
linear.setText(N.toString());
}
public String stf(String a,Integer l) {
if(l==0) { return a; }
l--;
return stf("0"+a,l);
}
public void click2(View view) {
String col1;
String col2;
// String playerChanged;
TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
EditText editText = (EditText)findViewById(R.id.simpleEditText);
TableRow row = new TableRow(this);
TextView tv = new TextView(this);
TextView c = new TextView(this);
//EditText etUserInfoNewValue = (EditText)findViewById(R.id.simpleEditText);
// a = editText.getText().toString();
tv.setId(202);
tv.setText("This is text");
//
tl.addView(row);
row.addView(tv);
int sf=Integer.toBinaryString(N-1).length();
for (int x = 0; x < N; x++) {
//String.format("%010d",(
String jl=Integer.toBinaryString(x);
String jl2=stf(jl,sf-jl.length());
koal[x]=jl2;
col1 = "(" + x + ")"+jl2;
// col1 = "(" + x + ")"+Integer.toBinaryString(x);
col2 = "1";
//col3 = "(" + x + ") Column 3";
//col4 = "(" + x + ") Column 4";
TableRow newRow = new TableRow(this);
TextView column1 = new TextView(this);
TextView column2 = new TextView(this);
EditText editText1 = new EditText(this);
editText1.setId(330+x);
// String stringAnswer = editText1.getText().toString();
TextView column3 = new TextView(this);
// TextView column4 = new TextView(this);
editText1.setText("0 ");
column1.setText(col1);
column1.setText(col1);
column2.setText(col2);
//column3.setText(col3);
//column4.setText(col4);
// column1.setText(stringAnswer);
newRow.addView(column1);
newRow.addView(editText1);
newRow.addView(column3);
// newRow.addView(column4);
tl.addView(newRow, new TableLayout.LayoutParams());
}
}
}
XML FILE
Kód: Vybrat vše
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android2="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_columnSpan="12"
android:layout_columnWeight="12"
android:accessibilityLiveRegion="none"
android:orientation="vertical">
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TableLayout>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click2"
android:text="Button2" />
<EditText
android:id="@+id/simpleEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:digits="10"
android:hint="Enter Your Name Here"
android:inputType="text" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="click4"
android:text="Button4" />
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="click5"
android:text="Button5" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Shapley1" />
</LinearLayout>
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
hmmm tady moc nerozumim zadani, mozna nejak jednoduseji co to ma udelat? Matematicka zadani mi nikdy moc nesly
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Aha, a ja to napsal jak nejsrozumitelneji a nejjednoduseji to slo.
Zkopiruj sem vse pokud az rozumis. Nebo nejak oznac vse co je nejasne, kde se ztracis,co mam vysvetlit
Taky je moznost, ze si aplikaci zkompilujes a nahrajes do mobilu a napravo zadas pro nejake vstupy 0 a 1, a zadas kolik je koalici, nejlepe mocninu 2, muzes zkusit 2,4, ci 8.
Zkopiruj sem vse pokud az rozumis. Nebo nejak oznac vse co je nejasne, kde se ztracis,co mam vysvetlit
Taky je moznost, ze si aplikaci zkompilujes a nahrajes do mobilu a napravo zadas pro nejake vstupy 0 a 1, a zadas kolik je koalici, nejlepe mocninu 2, muzes zkusit 2,4, ci 8.
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Mam maly problem, chtel bych uzivatelsky vstup v MultiLineTextArea mit velkym pismem.
Zadal jsem proto
android:capitalize="characters"
ale krome toho, ze je to v XMLku preskrtnute to ani navic nefunguje.
Nechci hledat jine reseni, rad bych zprovoznil toto, slo by to ?
Dekuji
Zadal jsem proto
android:capitalize="characters"
ale krome toho, ze je to v XMLku preskrtnute to ani navic nefunguje.
Nechci hledat jine reseni, rad bych zprovoznil toto, slo by to ?
Dekuji
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
zkus toto
Kód: Vybrat vše
android:inputType="textMultiLine|textCapCharacters"
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Bohuzel tato rada nefunguje:
Kód: Vybrat vše
<EditText
android:id="@+id/editTextTextMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:cursorVisible="true"
android:drawableBottom="@drawable/ic_launcher_background"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine|textCapCharacters" />
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
divne, mne to na emulatoru API 28 funguje, konkretne to mam takto. Nemenis na tom EditTextu pak jeste neco v kodu?
Kód: Vybrat vše
<EditText
android:id="@+id/multi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:inputType="textMultiLine|textCapCharacters"
android:ems="10"
tools:text="Dobry den, cely den"
/>
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
app a tools me sviti cervene a kdyz to smazu, tak se pise opet malm pismem
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Davam sem CELE XMLko.
Kód: Vybrat vše
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:foregroundGravity="fill_horizontal|top|bottom|right"
android:foregroundTint="@color/teal_200"
android:foregroundTintMode="src_over"
android:scrollbarDefaultDelayBeforeFade="10">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="12"
android:layout_columnWeight="12"
android:accessibilityLiveRegion="none"
android:orientation="vertical">
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"></TableLayout>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#1DE9B6"
android:onClick="click2"
android:textSize="10dp"
android:text="Generate"
android:textColor="#000000" />
<EditText
android:id="@+id/simpleEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:digits="10"
android:hint="Number of coalitions appear here"
android:inputType="text"
android:minHeight="48dp"
android:textColor="#FF0000" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="12"
android:layout_columnWeight="12"
android:accessibilityLiveRegion="none"
android:orientation="horizontal">
<Button
android:id="@+id/button4"
android:layout_width="25mm"
android:layout_height="wrap_content"
android:foregroundTint="#FF0000"
android:foregroundTintMode="src_over"
android:textSize="11dp"
android:onClick="click4"
android:scrollbarDefaultDelayBeforeFade="4"
android:text="Increase" />
<Button
android:id="@+id/button7"
android:layout_width="25mm"
android:layout_height="wrap_content"
android:foregroundTint="#FF0000"
android:foregroundTintMode="src_over"
android:textSize="11dp"
android:onClick="click7"
android:scrollbarDefaultDelayBeforeFade="4"
android:text="Decrease" />
</LinearLayout>
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#00E5FF"
android:backgroundTintMode="add"
android:foregroundTint="#000000"
android:onClick="click5"
android:text="Power indices" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapCharacters"
android:text="Shapley and Banzhaf" />
<EditText
android:id="@+id/editTextTextMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:cursorVisible="true"
android:drawableBottom="@drawable/ic_launcher_background"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine|textCapCharacters" />
<EditText
android:id="@+id/multi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:inputType="textMultiLine|textCapCharacters"
android:ems="10"
tools:text="Dobry den, cely den"
/>
</LinearLayout>
</ScrollView>
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
app a tools nema v tomto roli, tak muze byt smazano. A na jake verzi emulatoru to zkousis?
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Nevim, zda je moje odpoved spravna, ale pise mi to
Android 12.0
Nezkousim emulator ale mam mobil s poslednim Androidem pripojeny kabelem primo k PC.
Vubec nechapu, proc nefunguje
android:capitalize="characters"
a proc je to preskrtnute ?
Dekuji
Android 12.0
Nezkousim emulator ale mam mobil s poslednim Androidem pripojeny kabelem primo k PC.
Vubec nechapu, proc nefunguje
android:capitalize="characters"
a proc je to preskrtnute ?
Dekuji
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Problem nalezen!
Ja mel klavesnici T9 namisto originalni a kdyz ji vypnu funguje vse spravne.
Diky za trpelivost.
Ja mel klavesnici T9 namisto originalni a kdyz ji vypnu funguje vse spravne.
Diky za trpelivost.
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
kdyz je to preskrtnute, tak to znamena, ze je to depercated, ze se to uz v novejsich verzich androida nepouziva, nebo nebude pouzivat
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Mam jeste otazecku: existuje v Atrributes u TextView policko, po jehoz zaskrtnuti text je bezici po strane mobilu
zleva doprava ? Nasel jsem Gravity, ale to je jen staticke umisteni, text se nepohybuje/nerotuje jak bych chtel.
zleva doprava ? Nasel jsem Gravity, ale to je jen staticke umisteni, text se nepohybuje/nerotuje jak bych chtel.
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
dela se to nejak takto, android:ellipsize
https://stackoverflow.com/questions/330 ... n-activity
https://stackoverflow.com/questions/330 ... n-activity
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Dival jsem se na odkaz, ale pri zkopirovani do projektu mi sviti cervene toto
TextUtils:
txt.setEllipsize(TextUtils.TruncateAt.MARQUEE);
Co mam importovat ci jak to mam nastavit ?
Dekuji
TextUtils:
txt.setEllipsize(TextUtils.TruncateAt.MARQUEE);
Co mam importovat ci jak to mam nastavit ?
Dekuji
- Crusty
- Robot
- Příspěvky: 938
- Registrován: ned 19. črc 2009 17:30:40
- Typ mobilu / ROM: Redmi Note 9 Pro
- Bydliště: Praha
- Kontaktovat uživatele:
Re: potize s vyvojem aplikace, uzivatelsky vstup
to co to nabidne, kdyz na to cervene das kurzor a pak kliknes Alt+Enter (na Windows) tak to nabidne moznost importu
Melo by to byt android.text.TextUtils
Melo by to byt android.text.TextUtils
-
- Stálý androiďák
- Příspěvky: 55
- Registrován: čtv 17. úno 2022 18:15:35
- Typ mobilu / ROM: flizp z 3 samsung
Re: potize s vyvojem aplikace, uzivatelsky vstup
Naimportoval jsem, ale text je stale staticky, prikladam kod z MainActivity.java
Vyhledej prosim MARQUEE a zkus najit proc je staticky.
Do dalsiho komentu prikladam XMLko takze mas vse.
Vyhledej prosim MARQUEE a zkus najit proc je staticky.
Do dalsiho komentu prikladam XMLko takze mas vse.
Kód: Vybrat vše
package com.example.tablelayout6;
import androidx.appcompat.app.AppCompatActivity;
import android.icu.text.MeasureFormat;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TableRow;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.TableLayout;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import java.lang.StringBuilder;
public class MainActivity extends AppCompatActivity {
public boolean g=true;
public Integer N=1;
public String a="2";
private EditText editText1;
private EditText linear;
private Integer[] hodnoty =new Integer[10];
private String[] koal=new String[10];
private float[] shap=new float[10];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean iswinning(Integer J,int ii) {
return true;
}
public Integer fact (Integer f) {
if (f==0) return 1;
else return f*fact((Integer) (f-1));
}
//T pocetHracu
public Integer[] stringToArray(String binary) {
Integer[] arrayOfPLayers=new Integer[binary.length()];
for(int i=0;i<binary.length();i++) {
arrayOfPLayers[i]=Integer.parseInt("" + binary.charAt(i));
}
return arrayOfPLayers;
}
//N je pocet koalici
public void click5(View view) {
int pocetHracu=Integer.toBinaryString(N-1).length();
Integer[][] koalice=new Integer[N][pocetHracu];
Integer[][] koalice2=new Integer[N][pocetHracu];
Integer[][] koalice3=new Integer[N][pocetHracu];
TextView tv6 = (TextView) findViewById(R.id.textView6);
for (Integer ith=0;ith<N;ith++) {
for(Integer T=0;T<pocetHracu;T++) {
String StringPadded=stf(Integer.toBinaryString(ith),pocetHracu-Integer.toBinaryString(ith).length());
koalice[ith][T]=stringToArray(StringPadded)[T];
koalice2[ith][T]=stringToArray(StringPadded)[T];
koalice3[ith][T]=stringToArray(StringPadded)[T];
}
}
float[] shap=new float[pocetHracu];
float[] vyhryKoalici = new float[N];
Integer[] isSwing=new Integer[pocetHracu];
for (int i=0; i<N;i++) {
editText1 = (EditText) findViewById(330+i);
String a=editText1.getText().toString();
float f1 = Float.parseFloat(a);
vyhryKoalici[i]=f1;
}
Integer[] kolikJeSwingu= new Integer[pocetHracu];
String S="";
String kde="j";
Integer jth;
for (int p = 0; p < pocetHracu; p++) {
isSwing[p] =0;
kolikJeSwingu[p]=N;
}
// Integer swingove2=pocetHracu*N;
Integer bool=1;
Integer canBanzhaf=1;
for(Integer contr=0;contr<N;contr++)
{
if(vyhryKoalici[contr]!=0 && vyhryKoalici[contr]!=1) {
canBanzhaf=0;
}
}
for(Integer T=0;T<pocetHracu;T++) {
for (Integer ith = 0; ith < N; ith++) {
bool = 1;
//vyhryKoalici[ith];
//musis najit jth<N pro ktere koalice3[jth]=S-ith
if ((koalice[ith][T] == 1) && (vyhryKoalici[ith]==1)) {
koalice3[ith][T] = 0;
for (jth = 0; jth < N; jth++) {
for (Integer k = 0; k < pocetHracu; k++)
{
//if (k != T && koalice[ith][k] != koalice3[jth][k]) {
if ((k != T) && (koalice[ith][k] != koalice3[jth][k])) {
bool = 0;
// swingove2--;
kde+="\nk"+k.toString()+"T"+T.toString()+">";
}
}
kde+="\njth"+jth.toString()+"ith"+ith.toString()+"T"+T.toString();
//(vyhryKoalici[jth]
if ((vyhryKoalici[jth]==0) && (bool == 1)) {
isSwing[T]++;
}
bool=1;
}
koalice3[ith][T]=1;
bool=1;
}
}
}
//kolikJeSwingu(Integer TmaSwing, Integer pocetHracu, Integer pocetKoalici,
// Integer[][] koal, Integer[] koalicePriKtereJeSwing, float[] vyhryKoal)
for (Integer ith = 0; ith < N; ith++) {
for(Integer T=0;T<pocetHracu;T++) {
//isSwingBool(Integer kteraKoalice, Integer TmaSwing, Integer pocetHracu, Integer pocetKoalici,
// Integer[][] koal, Integer[] koalicePriKtereJeSwing, float[] vyhryKoal) {
// kolikJeSwingu[T]+=kolikJeSwingu(T, pocetHracu, N,
// koalice, koalice[ith],vyhryKoalici);
if (koalice[ith][T] == 1) {
koalice2[ith][T] = 0;
for (jth = 0; jth < N; jth++) {
bool = 1;
for (int k = 0; k < pocetHracu; k++) {
if (k != T && koalice[ith][k] != koalice2[jth][k]) {
bool = 0;
}
}
int bool2=0;
koalice2[ith][T] = 1;
if (vyhryKoalici[ith] == 1 && vyhryKoalici[jth] == 0) {
for (int k = 0; k < pocetHracu; k++) {
if (koalice[ith][k] != koalice2[jth][k]) {
bool2++;
}
}
// if(bool2==1) {
// isSwing[T]++;
// }
}
koalice2[ith][T] = 1;
Integer t = 0;
for (int p = 0; p < pocetHracu; p++) {
t += koalice[ith][p];
}
// Integer[] isSwing=new Integer[pocetHracu];
if (bool == 1) {
shap[T] += (float) ((float) fact(t - 1) * fact(pocetHracu - t) / (float) (fact(pocetHracu)) * (float) (vyhryKoalici[ith] - vyhryKoalici[jth]));
}
}
}
}
}
S+="here";
String T2="";
T2+="banzhaf";
Integer swingove=0;
for(int p=0;p<pocetHracu;p++) {
swingove+=isSwing[p];
}
String strPokus="";
if(canBanzhaf==1) {
strPokus = "banzhaf ";
} else {
strPokus="banzhaf err ";
}
float[] banzh=new float[pocetHracu];
for(int p=0;p<pocetHracu;p++)
{
banzh[p]=(float) isSwing[p]/(float) swingove;
}
String strPokus2="shap ";
for(int i=0;i<pocetHracu;i++) {
// S+=(" "+String.valueOf(shap[i]));
strPokus2+=String.format("%.2f ",shap[i]);
strPokus+=String.format("%.2f ",banzh[i]);
}
// tv6.setText(strPokus2+"\n"+strPokus+"\nswing"+isSwing[0]+"swingPrvni:"+isSwing[1]+"\nH"+swingove);
tv6.setText(strPokus2+"\n"+strPokus);
TextView txt = new TextView(this);
txt.setText("This is the infinite marquee");
txt.setEllipsize(TextUtils.TruncateAt.MARQUEE);
txt.setSingleLine(true);
txt.setMarqueeRepeatLimit(-1);
txt.setSelected(true);
}
public void click4(View view) {
//
if (g) {
linear = (EditText) findViewById(R.id.simpleEditText);
if (N == 1) {
linear.setText("1");
}
String a = linear.getText().toString();
N = Integer.parseInt(a);
N++;
linear.setText(N.toString());
}
}
public void click7(View view) {
if (g) {
//
linear = (EditText) findViewById(R.id.simpleEditText);
if (N == 0 || N == 1) {
linear.setText("1");
}
String a = linear.getText().toString();
N = Integer.parseInt(a);
if (N > 1) N--;
linear.setText(N.toString());
}
}
public String stf(String a,Integer l) {
if(l==0) { return a; }
l--;
return stf("0"+a,l);
}
public void click2(View view) {
if (g) {
g = false;
String col1;
String col2;
// String playerChanged;
TableLayout tl = (TableLayout) findViewById(R.id.tableLayout1);
EditText editText = (EditText) findViewById(R.id.simpleEditText);
TableRow row = new TableRow(this);
TextView tv = new TextView(this);
TextView c = new TextView(this);
//EditText etUserInfoNewValue = (EditText)findViewById(R.id.simpleEditText);
// a = editText.getText().toString();
tv.setId(202);
tv.setText("This is text");
//
tl.addView(row);
row.addView(tv);
int sf = Integer.toBinaryString(N - 1).length();
for (int x = 0; x < N; x++) {
//String.format("%010d",(
String jl = Integer.toBinaryString(x);
String jl2 = stf(jl, sf - jl.length());
//koal[x]=jl2;
col1 = "(" + x + ")" + jl2;
// col1 = "(" + x + ")"+Integer.toBinaryString(x);
col2 = "1";
//col3 = "(" + x + ") Column 3";
//col4 = "(" + x + ") Column 4";
TableRow newRow = new TableRow(this);
TextView column1 = new TextView(this);
TextView column2 = new TextView(this);
EditText editText1 = new EditText(this);
editText1.setId(330 + x);
// String stringAnswer = editText1.getText().toString();
TextView column3 = new TextView(this);
// TextView column4 = new TextView(this);
editText1.setText("0 ");
column1.setText(col1);
column1.setText(col1);
column2.setText(col2);
//column3.setText(col3);
//column4.setText(col4);
// column1.setText(stringAnswer);
newRow.addView(column1);
newRow.addView(editText1);
newRow.addView(column3);
// newRow.addView(column4);
tl.addView(newRow, new TableLayout.LayoutParams());
}
}
}
}
Naposledy upravil(a) max2 dne úte 19. dub 2022 15:56:36, celkem upraveno 1 x.