3 Nisan 2013 Çarşamba

Android Tasarım Konusunda İpuçları

Merhaba Arkadaşlar bu yazıda arayüz tasarlama konusunda zorlanıyorsanız veya xml dosyalarıyla uğraşmak istemiyorsanız  işinizi kolaylaştıracak bi siteden bahsetmek istiyorum.



Bu siteyi kullanarak kolaylıkla istediğiniz tasarımları yapabilirsiniz . 

İyi Çalışmalar :)

Android Basit TODO List Yapımı

Bu uygulamamızda bir önceki dersimizde gördüğümüz options menü ve listview kullanarak  basit bir şekilde ekleme,silme ,güncelleme ve çıkış işlemlerinin yapmını görücez. Oluşturduğumuz projemizin tasarımıza göz atalım :

<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"
    android:background="@drawable/arka"
    tools:context=".MainActivity" >

     <EditText
         android:id="@+id/editText1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_alignParentRight="true"
         android:layout_alignParentTop="true"
         android:layout_marginTop="14dp"
         android:ems="10"
         android:hint="Buraya Yazınız..." >

        <requestFocus />
    </EditText>
     <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
         android:layout_below="@+id/editText1" >

    </ListView>

</RelativeLayout>
Şimdi de Java kodlarımıza bakalım:
package com.example.android2;

import java.util.ArrayList;
import java.util.Locale;



import android.os.Bundle;
import android.app.Activity;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnInitListener {
    EditText editText;
    ListView listView;
    ArrayList<String> arrayList;
    ArrayAdapter<String> arrayAdapter;
    TextToSpeech texttoSpeech;
    Integer a=1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText=(EditText)findViewById(R.id.editText1);
        listView=(ListView)findViewById(R.id.listView1);
        texttoSpeech= new TextToSpeech (this,this);
        texttoSpeech.setLanguage(Locale.ENGLISH);
        
        arrayList = new ArrayList<String>();
        arrayAdapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arrayList);
        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                
                
                editText.setText( arrayList.get(arg2).toString());
                a=(int) arrayAdapter.getItemId(arg2);
                
                
            }
        });
    
}
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    
    case R.id.menuKaydet:
        if(!editText.getText().equals(null)){
        arrayList.add(editText.getText().toString());
        listView.setAdapter(arrayAdapter);
        editText.setText("");
        Toast.makeText(getApplicationContext(), "Kaydedildi.", Toast.LENGTH_LONG).show();
        }
        break;
    case R.id.menuGuncelle:
    
          arrayList.remove(a-1);
        
          arrayList.add(editText.getText().toString());
            listView.setAdapter(arrayAdapter);
            arrayAdapter.notifyDataSetChanged();
            editText.setText("");
        a=a+1;
        
        Toast.makeText(getApplicationContext(), "Güncellendi.", Toast.LENGTH_LONG).show();
        
        break;
    case R.id.menuSil:
         arrayList.remove(editText.getText().toString());
         listView.setAdapter(arrayAdapter);
         editText.setText("");
        Toast.makeText(getApplicationContext(), "Silindi", Toast.LENGTH_LONG).show();
        break;
    case R.id.menuCikis:
        finish();
        Toast.makeText(getApplicationContext(), "Çıkış yapıldı.", Toast.LENGTH_LONG).show();
        texttoSpeech.speak("closing", TextToSpeech.QUEUE_ADD,null);
        break;
    default:
        break;
        
    }
    return false;
    
    
    
}
@Override
public void onInit(int arg0) {
    // TODO Auto-generated method stub
    
}

}

 Texttospeech özelligini kullanarak  texttoSpeech.speak("closing", TextToSpeech.QUEUE_ADD,null); bu komutta görüldüğü gibi closing yazısının okunmasını sağlıyoruz. 

Uygulamamızın ekran görüntüsü :