Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

ListView set the item as checked to be highlighted



Important: Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB

int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
android.R.layout.simple_list_item_activated_1 :
android.R.layout.simple_list_item_1;


getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setItemChecked(position, true);


Example of usage:


public void updateList() {
		Context ctx = getActivity();
		Notes notes = new Notes(ctx);

		String[] from = { Notes.COLUMN_TITLE };
		int[] to = { android.R.id.text1 };
		int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
				android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1;
		ListAdapter adapter = new SimpleCursorAdapter(ctx,
				layout, notes.getNotes(), from,
				to, 0);

		setListAdapter(adapter);

		notes.close();
	}

/..................
@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        
        // Set the item as checked to be highlighted when in two-pane layout
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        getListView().setItemChecked(position, true);
     
    }


397LW NO topic_id



Další témata ....(Topics)


70

Foreach loop cycle in Java Android example | foreach-loop-cycle-in-java-android-example


Foreach in Java basic example source code.

MainClass.java


public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };

		for (String s : arrayOfString)
			System.out.println(s);

	}
}

306

xml string with html tags Android | xml-string-with-html-tags-android



// in strings.xml
<string name="myStringWithTags"><![CDATA[<b>some text..</b> other tags ...]]></string>
<string name="myStringWithPattern"><![CDATA[<b>%s</b> other tags ...]]></string>
// in Activity.class
String sHtmlText = this.getApplicationContext().getString(R.string.myStringTags);
         sHtmlText = this.getApplicationContext().getString(R.string.myStringWithPattern,"replace %s with this text");
117

AlertDialog yes no - Alert - Messagebox - Android sample | alertdialog-yes-no-alert-messagebox-android-sample


Dialog Yes No sample code

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit application?")
       .setCancelable(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                MyActivity.this.finish(); //Close  this Activity for example: MyActivity.java
           }
       })
       .setNegativeButton("No", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                // some code if you want
                dialog.cancel();
           }
       });
AlertDialog alert = builder.create();
alert.show();
189

NoClassDefFoundError: com.google.ads.AdView ADT 17 | noclassdeffounderror-com-google-ads-adview-adt-17


Eclipse update ADT 17 Android Emulator error: E/AndroidRuntime(370): java.lang.NoClassDefFoundError: com.google.ads.AdView

Solution:
-right click on the project in project tree and select Project properties
-select Java Build Path
-select TAB Order and Export
-check GoogleAdMobAdsSdk-4.0.4.jar (or your version SDK)
-press OK
-clean project by menu Project -> Clean
-rebuild project (Project - Build Automatically)

How add GoogleAdMobAdsSdk....jar to project:
-right click on the project in project tree and select Project properties
-select Java Build Path
-select TAB Libraries
-press the button Add External JARs...
-select your version GoogleAdMobAdsSdkXXX.jar what you can using
-OK
-OK
-clean project
-rebuild project


menu-item-project-properties-eclipse
order-and-export-eclipse dialogue
eclipse-add-jar-library-to-project
25

Copy sqlite database from apk package to device folder Android example | copy-sqlite-database-from-apk-to-device-folder-android-example


Put your sglite database to Android Eclipse project folder named Assets.
On device will copy database file to application folder as this example:



 public void createDatabase(Context myContext) throws IOException {
    String sPackName = myContext.getPackageName();
    InputStream assetsDB = myContext.getAssets().open("myDatabase");
    OutputStream dbOut = new FileOutputStream("/data/data/"+sPackName+"/database");
 
    byte[] buffer = new byte[1024];
    int length;
    while ((length = assetsDB.read(buffer))>0){
      dbOut.write(buffer, 0, length);
    }
 
    dbOut.flush();
    dbOut.close();
    assetsDB.close();
}




Editace Jana Žákovská : 2016-06-24 14:11:50
Počet článků v kategorii: 397
Url:listview-set-the-item-as-checked-to-be-highlighted
Share
Share
Tweet