Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
MOBIL QQSHA.docx
Скачиваний:
0
Добавлен:
27.11.2023
Размер:
6.09 Mб
Скачать

Edit text komponentası hám onnan paydalanıw

Edittext – bul tekst kiritiw ushın arnalǵan komponenta bolıp, TextView klasınıń násili bolıp tabıladı.

Edittext komponentası qollanbalarda tómendegi súwrettegidey kóriniske iye boladı.

XML definition for a very basic EditText control 

<EditText

        android:id="@+id/editTextSimple"

        android:layout_height="wrap_content"

        android:layout_width="match_parent">

</EditText>

Retrieving the Value of an EditText Control Programmatically

final EditText simpleEditText = (EditText) findViewById(R.id.editTextSimple);

String strValue = simpleEditText.getText().toString();

Monitoring an EditText Control for Actions

setOnClickListener() – EditText basılǵanda isleydi

setOnLongClickListener() - EditText uzaq basılǵanda isleydi

setOnKeyListener() - EditText ke klaviaturadan qandayda bir simvol kiritilgende isleydi

setOnFocusChangedListener() – qollanba interfeysinde EditText ke fokus alınǵanda shaqırıladı

final EditText simpleEditText = (EditText) findViewById(R.id.editTextSimple);

simpleEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

public void onFocusChange(View v, boolean hasFocus) {

String strValue = simpleEditText.getText().toString();

Log.d(DEBUG_TAG, "User set EditText value to " + strValue);

}

});

EditText ge kiritilgen maǵlıwmatlar tipleri hám qosımsha komponentaları

android:inputType="phone"

android:inputType="textPassword"

android:hint="@string/hint"

android:capitalize="sentences" –

android:digits="01"

android:cursorVisible="false"

EditText komponentasınıń qásiyetleri

Qásiyeti

Anıqlaması

android:textSize

Tekst ólshemi. Tekst ólshemin ornatıwdıń bir neshe usılı bar. px (piksel), dp, sp, in (dyum), pt, mm. Tekstlerge ólshem ornatıwda sp nı qollanıw usınıladı. android:textsize=”48sp”

android:textStyle

Tekst stili. Normal, bold, italic mánisleri isletiledi.

Máselen: android:textStyle="bold"

android:textcolor

Tekst reńi. Reńler 4 túrli formada beriledi: #RGB; #ARGB; #RRGGBB; #AARRGGBB, háripler R, G, B reńlerdi, A ayqınlıqtı (kórinip turatuǵın) bildiredi (alpha - channel). A mánisi 0 bolsa, 100% ayqınlıq.

...

...

5 - Ámeliy jumıs: Android ta paydalanıwshı interfeysin jaratıw. Gelereya hám súwretlerdi jaylastırıw

Jumıstan maqset: Android sistemasında paydalanıwshı interfeysin jaratıw. Gallery, ImageView hám ImageSwitcher komponentalarınan paydalanıp súwretlerdi kórsetetuǵın qollanba jaratıw kónlikpelerine iye bolıw.

Máseleniń qoyılıwı:Student berilgen variant boyınsha Gallery, ImageView hám ImageSwitcher komponentalarınan paydalanıp Galereya programmasın jaratıwı kerek:

Máseleni sheshiw ushın úlgi:

  1. Eclipse (ADT)da “Gallery” atamasında proekt jaratıń

  2. Qollanbada kerekli bolǵan súwretlerdi res/drawable-mdpi papkasına kóshiriń (mısalı ushın pic1.png, pic2.png h.t.b.)

  3. Proekt faylların sáykes halda ózgertiń

    1. MainActivity.java(src papkasında jaylasqan tiykarǵı aktivity fayl)

    2. main.xml (res/layout papkasında jaylasqan layout fayl)

  4. Qollanbanıń res/values papkasına attrs.xml atlı fayldı qosıń

  5. Nátiyjede qollanbanıń papkalar strukturası tómendegishe boladı (1-súwret)

1-súwret. Usı qollanbanıń fayllar strukturası

  1. Sáykes túrde fayllardıń kodları tómende keltirilgen

MainActivity.java

package package atı kiritilsin (com.example.gallery)

import android.app.Activity;

import android.os.Bundle;

import android.content.Context;

import android.content.res.TypedArray;

import android.view.View;

import android.view.ViewGroup;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.BaseAdapter;

importandroid.widget.Gallery;

import android.widget.ImageView;

import android.widget.Toast;

publicclass MainActivity extends Activity {

//---the images to display---

Integer[] imageIDs = {

R.drawable.pic1,

R.drawable.pic2,

R.drawable.pic3,

R.drawable.pic4,

R.drawable.pic5,

R.drawable.pic6,

R.drawable.pic7

};

/** Called when the activity is first created. */

@Override

publicvoid onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Gallery gallery = (Gallery) findViewById(R.id.gallery1);

gallery.setAdapter(new ImageAdapter(this));

gallery.setOnItemClickListener(new OnItemClickListener()

{

publicvoid onItemClick(AdapterView<?> parent, View v, int position, long id)

{

Toast.makeText(getBaseContext(),

"pic" + (position + 1) + " selected",

Toast.LENGTH_SHORT).show();

//---display the images selected---

ImageView imageView = (ImageView) findViewById(R.id.image1);

imageView.setImageResource(imageIDs[position]);

}

});

}

publicclass ImageAdapter extends BaseAdapter

{

private Context context;

privateintitemBackground;

public ImageAdapter(Context c)

{

context = c;

//---setting the style---

TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);

itemBackground = a.getResourceId(

R.styleable.Gallery1_android_galleryItemBackground, 0);

a.recycle();

}

//---returns the number of images---

publicint getCount() {

returnimageIDs.length;

}

//---returns the ID of an item---

public Object getItem(int position) {

return position;

}

//---returns the ID of an item---

publiclong getItemId(int position) {

return position;

}

//---returns an ImageView view---

public View getView(int position, View convertView, ViewGroup parent) {

ImageView imageView = new ImageView(context);

imageView.setImageResource(imageIDs[position]);

imageView.setScaleType(ImageView.ScaleType.FIT_XY);

imageView.setLayoutParams(newGallery.LayoutParams(150, 120));

imageView.setBackgroundResource(itemBackground);

return imageView;

}

}

}

main.xml

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

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:text="Images of San Francisco"/>

<Gallery

android:id="@+id/gallery1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"/>

<ImageView

android:id="@+id/image1"

android:layout_width="320px"

android:layout_height="250px"

android:scaleType="fitXY"/>

</LinearLayout>

attrs.xml

<?xmlversion="1.0"encoding="utf-8"?>

<resources>

<declare-styleablename="Gallery1">

<attrname="android:galleryItemBackground"/>

</declare-styleable>

</resources>

Programma nátiyjesi

Tema boyınsha variantlar:

Variant

Studentler sanı

Students Gallery

1

Computers Gallery

1

Samsung TVs Gallery

1

Samsung Phones Gallery

1

Books Gallery

1

Universities Gallery

1

Foods Gallery

1

National Foods Gallery

1

Football Stars Gallery

1

Man’sclothes Gallery

1

Woman’s clothes Gallery

1

Cars Gallery

1

Mountains Gallery

1

Scientists Gallery

1

Cities Gallery

1

Historical Places Gallery

1

Flowers Gallery

1

IPhones Gallery

1

Tablets Gallery

1

Printers Gallery

1

Fruits Gallery

1

Vegetables Gallery

1

Child Toys Gallery

1

Airplanes Gallery

1

Animals Gallery

1

Birds Gallery

1

Towers Gallery

1

Watches Gallery

1

Cinema Gallery

1

Artists Gallery

1

6- Ámeliy jumıs: Androidta paydalanıwshı interfeysin jaratıwda Maǵlıwmatlar bazasınan paydalanıw. SharedPreference obyekti hám fayllar sistemasınan paydalanıw

Jumıstan maqset: Androidta paydalanıwshı interfeysin jaratıwda Maǵlıwmatlar bazasınan paydalanıw. SharedPreference obyekti hám fayllar sistemasınan paydalanıw kónlipelerine iye bolıw. FileInputStream, FileOutputStream, InputStreamReader, OutputStreamWriter klasslarınan paydalanıw.

Máseleniń qoyılıwı:Student berilgen variant boyınsha qollanba jaratıp qollanbaǵa tiyisli bolǵan maǵlıwmatlardı SharedPreference obyekti arqalı xml faylına hám txt g=faylına jazıwı hám DDMS qásiyetlerinen paydalanıp nátiyje alıwi kerek:

Máseleni sheshiw ushın úlgi:

  1. SharedPreference obyektinen paydalanıw

2. Fayllar sistemasınan paydalanıw SharedPreference obyektinen paydalanıw

  1. Jańa Android proekt jaratamız hám onı GameSettingPreference dep ataymız.

  2. /res papkasınada xml atlı jańa papkalar jaratamız hám onıń ishine settingpreference.xml atlı xml fayl jaratamız (súwrette kórsetilgendey)

  3. package ishinde SettingActivity.java atlı jańa klass jaratıladı

  4. Sáykes túrde programma fayllarınıń kodları tómende keltirilgen.

/res/layout/activity_main.xml

<RelativeLayoutxmlns: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:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity">

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world"/>

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/textView1"

android:layout_alignParentRight="true"

android:layout_below="@+id/textView1"

android:layout_marginTop="29dp"

android:text="@string/play"/>

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/button1"

android:layout_alignRight="@+id/button1"

android:layout_below="@+id/button1"

android:layout_marginTop="32dp"

android:text="@string/profile"/>

<Button

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/button2"

android:layout_alignRight="@+id/button2"

android:layout_below="@+id/button2"

android:layout_marginTop="38dp"

android:text="@string/setting"

android:onClick="callSetting"/>

<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/button3"

android:layout_alignRight="@+id/button3"

android:layout_below="@+id/button3"

android:layout_marginTop="34dp"

android:text="@string/exit"/>

</RelativeLayout>

string.xml

<?xmlversion="1.0"encoding="utf-8"?>

<resources>

<stringname="app_name">GameSettingPreference</string>

<stringname="action_settings">Settings</string>

<stringname="hello_world">Using setting preferences!!!</string>

<stringname="play">Play</string>

<stringname="profile">Profile</string>

<stringname="setting">Settings</string>

<stringname="exit">Exit</string>

</resources>

settingpreference.xml

<?xmlversion="1.0"encoding="utf-8"?>

<PreferenceScreen

xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategoryandroid:title="Change game settings">

<CheckBoxPreference

android:title="Music"

android:defaultValue="true"

android:summary="uncheck to switch off music"

android:key="music"/>

<CheckBoxPreference

android:title="Sound"

android:defaultValue="true"

android:summary="uncheck to switch off sound"

android:key="sound"/>

<CheckBoxPreference

android:title="Repeat"

android:defaultValue="false"

android:summary="Repeat game"

android:key="repeat"/>

<CheckBoxPreference

android:title="Online"

android:defaultValue="false"

android:summary="play online"

android:key="online"/>

</PreferenceCategory>

</PreferenceScreen>

MainActivity.java

importandroid.os.Bundle;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.util.Log;

import android.view.Menu;

importandroid.view.View;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

public void callSetting(View v){

Log.d("Button","Setting menu is called!!!");

Intent intent = new Intent(this,SettingActivity.class);

startActivity(intent);

}

}

SettingActivity.java

importandroid.os.Bundle;

importandroid.preference.PreferenceActivity;

public class SettingActivity extends PreferenceActivity {

@SuppressWarnings("deprecation")

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//to change preference file name add this code

addPreferencesFromResource(R.xml.settingpreference);

}

}

AndroidManifest.java

……

<activityandroid:name=".SettingActivity"

android:label="@string/app_name">

<intent-filter>

<action

android:name="com.example.SettingActivity"/>

<categoryandroid:name="android.intent.category.DEFAULT"/>

</intent-filter>

</activity>

……

Соседние файлы в предмете Mobil qosimshalar