Showing posts with label Mobile. Show all posts
Showing posts with label Mobile. Show all posts

Wednesday, May 13, 2009

Android SDK's Guide, Image from Gallary to be Clickable

Android's Online Resource is very limited, it took me a day before I can figure out how to make those pictures in the photo gallery clickable. I am still a newbie at android development, but I have never spend this much time trying to figure out something that's this simple.

On the android's website it has Hello Gridview guide, which shows you the photo gallary. If you want further clicks from those photos following code is to be added.

All the XML has already set up in the tutorial.

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.photogridview);
gridview.setAdapter(new ImageAdapter(this));

gridview.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView parent, View v, int position, long id){
GoDoWhatever();
}}});
}

protected void GoDoWhatever()
{
//Do Whatever you want to do after pictures in the gallery are being clicked
}

Hopefully this helps

Wednesday, May 6, 2009

Android's Button Onclick Event:Button.OnClickListener()

I came from Asp.net background, and I really didn't have any idea on how to develop mobile phone applications. I didn't see any documentation on how get an event for OnClick on Android SDK, this most simple feature is can not be automatically generated by Eclipse, you have do it on your own.

in the \res\layout\main.xml Create the button

<button
id="@+id/TestButton"
layout_width="fill_parent"
layout_height="wrap_content"
layout_marginleft="30dip"
layout_marginright="30dip"
text="Test Button">

And you can reference it like this from code behind

---------------------------------------------------------
package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;

public class HelloAndroid extends Activity {
private Button btnFromGallery;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initControls();
}

protected void initControls()
{
btnFromGallery = (Button)findViewById(R.id.TestButton);

btnFromGallery.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ DoWork(); }});
}

protected void DoWork()
{
//Do whatever you need to do here
}
}
-------------------------------------------------------------------

This may look simple but it was very hard to find it online, I hope google would create more examples in the future.

Conversion to Dalvik format failed with error 1

I started google android development today, after downloading SDK and loading it into eclipse just like how google guide “hello android” has listed.

no classfiles specified
Conversion to Dalvik format failed with error 1
pops up as I try to run it for the very first time.

How you fix it is
Go to Project -> Clean and it should solve the problem.

Good luck on your “Hello Android Application”