37.XML faylda EditText komponentasini yaratib va Java fayl bilan bog’lab, kiritilgan ma’lumotni Toast ga chiqaring.
activity_main.xml faylida EditText komponentasini yaratamiz:
android:id="@+id/editText"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="text"/>
MainActivity.java da kiritilgan ma’lumotni Toast ga chiqaramiz:
package com.example.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button showBtn = findViewById(R.id.showBtn);
EditText editText = findViewById(R.id.editText);
showBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), editText.getText().toString(), Toast.LENGTH_LONG).show();
}
});
}
}
38.Androidda TableLayout xususiyatlarini misol bilan keltirib o’ting.
TableLayout konteyneri jadvaldagi boshqaruv elementlarini ustunlar va satrlar bo’yicha strukturalaydi. activity_main.xml faylida ikkita satr va ikkita ustundan iborat TableLayout elementini yaratamiz:
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_weight="0.5"
android:text="Логин"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_weight="0.5"
android:text="Email"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Dostları ilə paylaş: |