Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Friday, July 5, 2013

[android help] Android - How to create divider for ListView with rounded corners


Android - How to create divider for ListView with rounded corners


Android - How to create divider for ListView with rounded corners - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I want to give my ListView rounded corners and some padding. Here is my style:










But when I create a divider its width is not from one end to the other but looks like this:


enter image description here


I create the divider like this:



...
android:divider="@color/bordeaux"
android:dividerHeight="1px" />


Any ideas how to tell the divider to strech from one end to the other?


Thanks!





























For round corners I use








android:width="2dp"
android:color="#cccccc" />

android:bottom="0dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />

android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />




For separator I use this in the layout item xml



android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#cccccc" />



















default






Read more

stackoverflow.comm



Monday, June 10, 2013

[android help] Android - Need help accessing image from shared network


Android - Need help accessing image from shared network


networking - Android - Need help accessing image from shared network - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I'm creating an app that loads images from a network. I have internet permission and access network state permission but I get cannot open file error. I'm using the absolute path when specifying the file ie \\192.168.1.100\d\.folder\image.jpg.


Is this possible or is there something else that i need to do first?


























UNC paths (of the form \\\ will NOT work by default on Android: Android does not natively support those sort of references (CIFS). You should either use HTTP and one of the toolkits that provides support for that (like Volley) or look at a library like JCIFS.




















default






.

stackoverflow.comm

[android help] Android - create PDF and mail as attachment


Android - create PDF and mail as attachment



The main thing I am trying to do in my app is create a PDF file from data I have (table from ArrayList). After that being done, everything should be e-mailed as 1 attachment. The best way of doing this is by writing the file to the storage system en then passing it via mail, and afterwards deleting it again. Is it possible to create a File object or something like that and pass it immediately without having to write it to the file system? Also, caching is no option I believe because the mail app doesn't have access to my stored file from my app then.


For creating the PDF, I found a very nice and handy little thing called droidtext (http://code.google.com/p/droidtext/). I believe creating the PDF is no problem. However, the problems start at saving the file. Obviously I want to create the file on the external storage, as well as on the internal storage if the external storage is unavailable.


This is what I found for the part with creating the PDF. This piece of code only represents the internal storage, because I believe that is the problem. For external storage, I only need to work with Environment.getExternalStorageDirectory(), so that's no problem.



Document document = new Document();
try {
//hard coded for testing purpose
PdfWriter.getInstance(document, openFileOutput("test.pdf", Context.MODE_WORLD_WRITEABLE));//-->deprecated, why? Alternative?
document.open();
Table table = new Table(2, 2);
table.addCell("0.0");
table.addCell("0.1");
table.addCell("1.0");
table.addCell("1.1");
document.add(table);
document.add(new Paragraph("Table converted: "));
table.setConvert2pdfptable(true);
document.add(table);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
//the line below is a complete mistery for me, I've tried a lot here...
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///test.pdf"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{getResources().getString(R.string.mail_recipient)});
intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.mail_subject));
intent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.mail_body1));
startActivity(Intent.createChooser(intent, "E-mail"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}

document.close();


This code seems to work (I think) because it doesn't deliver errors in any kind. However, I can't locate the file on my device. I guess it should be in the root folder (/). Do the deprecated MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE have an alternative?


Every time now the mailing app starts (gmail on my phone), the attachment can't be sent. After looking for a few hours around the internet, I found that the MODE_WORLD_XXX should be used in order to have access with your mailing app.


Also I am not sure if I should close the document before mailing or after. It doesn't change anything in the log.


Also, why is the MODE_WORLD_XXX deprecated? Are there alternatives?


I am terribly sorry for all the questions, but it's now passed 4 am here.


Thanks in advance, kind regards :)!



.

stackoverflow.comm

Friday, May 17, 2013

[android help] Android - Which layout to listen to implement gestures in my application


I want my application to listen to gesture. Just a simple gesture l-r, r-l. So, from the main layout, when you swipe from left to right, a sidemenu appears. And when you swipe from right to left, side menu hides. But what i did was, I let sideMenu listen for the ontouch, so when the sidemenu is hidden, I can't show it by just swiping the mainlayout. But i managed to hide that sidemenu after it was shown because i tried to show it first.


So, i tried to listen from my multiColumnListView. It worked but now I can't scroll my multiColumnListView. Also, the problem with placing the listener in the multiColumnListView, when there's is no content, no one will listen the gesture.


enter image description here


The red, orange and maroon boxes are my headers and footers. The multiColumnListView is the broken yellow green box. Then the contents are the green boxes. Then the right image is when there is no content. This is my current layout:



xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ignoreGravity="@+id/sideMenu"
android:id="@+id/mainRelativeLayout">

android:id="@+id/frameLayout"
android:layout_below="@+id/header_1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

android:id="@+id/search_header"
layout="@layout/search_header" />

xmlns:pla="http://schemas.android.com/apk/res-auto"
android:id="@+id/multiColumnListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >


android:id="@+id/sideMenu" />



android:id="@+id/header_1"
android:layout_alignParentTop="true"
layout="@layout/header_1"/>




I tried listening from my RelativeLayout. Though it work but when there are contents, i should start the gesture from the left most part.



final GestureDetector gdt = new GestureDetector(this,new GestureListener());
sideMenu.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(final View view, final MotionEvent event) {
gdt.onTouchEvent(event);
return true;
}
});

final GestureDetector gest = new GestureDetector(this,new GestureListener());
mainLayout.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(final View v, final MotionEvent event) {
gest.onTouchEvent(event);
return true;
}
});


This is how i listen. I listen from my relativelayout and sidemenu. But I want also to listen from the center of my application eventhough there are contents(multicolumnlistview).


How can i listen from multicolumnlistview without ruining its scroll? Or are there other ways to listen for gestures? Any ideas? Help is greatly appreciated.



.

stackoverflow.comm

Thursday, May 9, 2013

[android help] Android, List Adapter returns wrong position in getView


I have found a mysterious problem that may be a bug! I have a list in my fragment. Each row has a button. List shouldn't respond to click however buttons are clickable.


In order to get which button has clicked I have created a listener and implement it in my fragment. This is the code of my adapter.



public class AddFriendsAdapter extends BaseAdapter {

public interface OnAddFriendsListener {
public void OnAddUserClicked(MutualFriends user);
}

private final String TAG = "*** AddFriendsAdapter ***";

private Context context;
private OnAddFriendsListener listener;
private LayoutInflater myInflater;
private ImageDownloader imageDownloader;
private List userList;

public AddFriendsAdapter(Context context) {
this.context = context;
myInflater = LayoutInflater.from(context);

imageDownloader = ImageDownloader.getInstance(context);
}

public void setData(List userList) {
this.userList = userList;

Log.i(TAG, "List passed to the adapter.");
}

@Override
public int getCount() {
try {
return userList.size();
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;

if (convertView == null) {
convertView = myInflater.inflate(R.layout.list_add_friends_row, null);
holder = new ViewHolder();

Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/ITCAvantGardeStd-Demi.ttf");
holder.tvUserName = (TextView) convertView.findViewById(R.id.tvUserName);
holder.tvUserName.setTypeface(font);
holder.ivPicture = (ImageView) convertView.findViewById(R.id.ivPicture);
holder.btnAdd = (Button) convertView.findViewById(R.id.btnAdd);
holder.btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e(TAG, "Item: " + position);
listener.OnAddUserClicked(userList.get(position));
}
});

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

holder.tvUserName.setText(userList.get(position).getName());
imageDownloader.displayImage(holder.ivPicture, userList.get(position).getPhotoUrl());

return convertView;
}

public void setOnAddClickedListener(OnAddFriendsListener listener) {
this.listener = listener;
}

static class ViewHolder {
TextView tvUserName;
ImageView ivPicture;
Button btnAdd;
}
}


When I run the app, I can see my rows however since my list is long and has over 200 items when i goto middle of list and click an item then returned position is wrong (it's something like 7, sometimes 4 and etc.).


Now what is the mystery? If I active on item listener of list from my fragment and click on row then correct row position will be displayed while on that row if I click on button then wrong position will be displayed.



listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
Log.e(TAG, "item " + position + " clicked.");
}
});


Result in logcat:



05-09 10:22:25.228: E/AddFriendsFragment(20296): item 109 clicked.
05-09 10:22:34.453: E/*** AddFriendsAdapter ***(20296): Item: 0


Any suggestion would be appreciated. Thanks



.

stackoverflow.comm

[android help] Android-NDK: Fatal signal 11 (SIGSEGV) on Windows 64 only

Android-NDK: Fatal signal 11 (SIGSEGV) on Windows 64 only - Stack Overflow








Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















When I run the project on my Mac everything is fine. The same project run on Windows 64 I crash upon start.


Both use NDK8e. How can I find out what is the difference?


Windows 64



05-09 04:25:51.310: D/dalvikvm(16908): Shared lib '/data/data/com.evotegra.aCoDriver/lib/libjsqlite.so' already loaded in same CL 0x4219e688
05-09 04:25:51.335: A/libc(16908): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 16908 (tegra.aCoDriver)


Mac



05-09 04:49:09.070: D/dalvikvm(307): Shared lib '/data/data/com.evotegra.aCoDriver/lib/libjsqlite.so' already loaded in same CL 0x4219d5f8
05-09 04:49:40.735: V/SoundPoolThread(27591): beginThread















Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.










default







.

stackoverflow.comm

Thursday, May 2, 2013

[android help] android - delete a row in sql and item in listview


i try to delete a row from my db. I'm using this method:


public void deletePlayerbyID(int id){mDb.delete(SQLITE_TABLE, KEY_ROWID +"="+id, null); }


called in activity :



listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView av, View v, int pos, long id) {
return onLongListItemClick(v,pos,id);
}
protected boolean onLongListItemClick(View v, final int pos, long id) {

AlertDialog.Builder builder = new AlertDialog.Builder(AndroidListViewCursorAdaptorActivity.this);
builder.setMessage("Are you sure to delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {bdHelper.open();
dbHelper.deletePlayerbyID(pos);
Log.i("ListView", "onLongListItemClick id=" + pos);
displayListView();
}
})


...........


why i can't delete the selected row from listView? i have a method that delete all db and it work.



.

stackoverflow.comm

Wednesday, May 1, 2013

[android help] Android - TextView not showing


I have a TextView that used to show on the screen, and did what I wanted. However, I streamlined some later code that repositions it with a touch to it's parent FrameLayout. Now, the TextView (named angleView) ceases to show on screen, but when I print out it's coordinates, it still works the same way. Can anyone see what I'm doing wrong?


Here is the code from my onCreate() method:



angleView = new TextView(getApplicationContext());
angleView.setTextColor(Color.RED);
angleView.setText("0");
angleView.setLayoutParams(new FrameLayout.LayoutParams(SCREEN_WIDTH/20, SCREEN_HEIGHT/20));


and the code from the FrameLayout's onTouchListener:



preview.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
float y = (centerPoint.getY() - event.getY() + STATUS_BAR_HEIGHT);
float x = (centerPoint.getX() - event.getX());
double angle = Math.atan(y/x);
setAngleFieldData(event, angle, y, x);
setFingerFollower(event, angle);
setYMeasure(event, y);
setXMeasure(event, x);
setTextPositions(event, angle, y, x);
Log.i("angleX", String.valueOf(angleView.getX()));
Log.i("angleY", String.valueOf(angleView.getY()));
return true;
}

private void setAngleFieldData(MotionEvent event, double angle, float y, float x){
angleView.setText(String.valueOf(angle));
angleView.setX(event.getX());
angleView.setY(event.getY());
if(isRadians) {
if(x < 0 && y >= 0){
angleView.setText(String.valueOf(2 * Math.PI + angle));
}
}

}


(the other methods are irrelevant, it used to be that all the code from the individual methods was in the onTouch.)


And in case you are wondering, yes, there is a:



preview.addView(angleView);


Many thanks!



.

stackoverflow.comm

[android help] onSizeChanged() calls onCreate() and onStart()? - Android


My app currently calls a method in the onCreate() method so that the game will start and animations will run once the view is created. However when i flip the screen to switch between portrait and landscape, this method is called again.


I've moved the calling line both to the onStart() method and even the methods class constructor.


this is the method that is being called:



public void startGame() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {

public void run() {
runGame();
}
}, 500);
}


There is a delay to allow everything to be constructed before it is run, otherwise it won't work.


Is there i way to stop onSizeChanged() affecting this method being called? Or is there a way i can call this method so that it starts when the activity is started (again so that onSizeChanged() cant affect it and that everything is initialized before its call).


Thanks for looking.



.

stackoverflow.comm

Friday, April 26, 2013

[android help] Android - sharing


Maybe you wanted a more complete answer because the accepted one was rather short, I'm a year too late but hopefully it's still useful :)


So here's a possible solution in handling multiple intents...


1) You want to know the result (eg succes or fail) of the intent?


Just start the intent using following line:



startActivityForResult(intent, 1); //instead of startActivity(intent)


And retrieve the requestCode and resultCode by overriding onActivityResult:



@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
if(resultCode == Activity.RESULT_OK){
//intent 0 = succesful (Facebook)
} else{
//intent 0 = failed or canceled
}
} else if (requestCode == 1) {
if(resultCode == Activity.RESULT_OK){
//intent 1 = succesful (Twitter)
} else{
//intent 1 = failed or canceled
}
}
}


2) You want to know which app the intent opened?


Don' trust the built-in intent chooser, make your own dialog and give each intent another requestCode (a unique integer-value, to identify the intent)


An example:



new AlertDialog.Builder(this)
.setTitle("Share with friends!")
.setSingleChoiceItems(new ArrayAdapter(this, android.R.layout.select_dialog_singlechoice,
new String[]{"Facebook", "Twitter"}), -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
StartFacebookShare();
} else if (which == 1) {
StartTwitterShare();
}
dialog.dismiss();
}
}).show();

private void StartFacebookShare() {
Intent intent = new Intent("android.intent.category.SEND");
intent.putExtra(Intent.EXTRA_SUBJECT, "URL");
intent.putExtra(Intent.EXTRA_TEXT, "http://www.stackoverflow.com");
intent.setClassName("com.facebook.katana", "com.facebook.katana.ShareLinkActivity");
startActivityForResult(intent, 0);
}
private void StartTwitterShare() {
String message = "www.stackoverflow.com"; //the string you want to tweet
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.twitter.android", "com.twitter.android.PostActivity");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivityForResult(intent, 1);
} catch (Exception e) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://twitter.com/intent/tweet?text=" + message));
startActivityForResult(intent, 1);
}
}


Some useful info can be found here and here, maybe search here or comment if you have suggestions for my code (I always like feedback ^^) or if you're stuck on something :)



.

stackoverflow.comm

Tuesday, April 23, 2013

[android help] android - strings.xml vs static constants


There are both some advantages and disadvantages ( I should say advantages and less advantages) in these two cases.


as in the comments of your question they said it all. I just want to add some minor points.


Localization:


For localization issue definitely String resource is the best as you can use different language file for differente Locale.


Memory:


As String resources are saved in xml file so there are some extra overhead (not a major one though)


Performance:


reading from memory is always faster than reading from file. Although in this case the performance difference is not significant


Maintainance:


It is just a personal opinion. To me maintaining res file is easier than maintaining string in class. string.xml is more readable to me.


Finally:


So my suggestion is




use string resources for the texts which will be displayed to user.


and



use static constants for internal puposes of your program like database names, internal variable, intent filter name etc.




.

stackoverflow.comm

Sunday, April 21, 2013

[android help] Android - How to work with nested ListViews


this is my first question on this site and I am also new to Android. I am creating an application using an online API. I am working with this API in XML and parsing the responses into ListViews. I have reached a point where I would like to select an item from a ListView in one activity and send that information to the next activity along with another ListView containing more information for the selected item. As an example, one activity has a list of bands. Clicking on the band name will bring up the band name and a list of tour dates on the next activity. According to my API, the band's ID number is needed to access the bands tour information I am trying to pass the ID number as a search parameter but cannot get this to work. I did manage to find a decent tutorial on androidhive.info but cannot seem to be able to apply these techniques. The doInBackground() method is where my app is hanging up.



ListView lv = getListView();

lv.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView parent, View view,
int position, long id) {
// getting values from selected ListItem
String displayName = ((TextView) view.findViewById(R.id.tvDisplayName)).getText().toString();
String onTourUntil = ((TextView) view.findViewById(R.id.tvOnTourUntil)).getText().toString();
String identification = ((TextView) view.findViewById(R.id.tvId)).getText().toString();

// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleArtistActivity.class);
in.putExtra(KEY_DISPLAY_NAME, displayName);
in.putExtra(KEY_ID, identification);
in.putExtra(KEY_ON_TOUR_UNTIL, onTourUntil);

new AsyncDownload().execute(identification);

startActivity(in);
}
});


}



private class AsyncDownload extends AsyncTask {

ProgressDialog pDialog;

@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ArtistsSearchActivity.this);
pDialog.setMessage("Please Wait...");

pDialog.setCancelable(false);
pDialog.show();
}

@Override
protected String doInBackground(String... params) {

Log.v(TAG, "query is" + params[0]);
String result = new ArtistCalendarHelper().getXml(params[0]);
return result;
}


My AsyncDownload class is called in my onClickListener. The class calls a helper that contains the URL and API key.



public class ArtistCalendarHelper {
private static final String TAG = "ArtistCalendarHelper";
private static final String SONGKICK_URL = "http://api.songkick.com/api/3.0/artists/";
private static final String API_KEY = "yIekMi1hQzcFheKc";

public String getXml(String identification) {

HttpClient httpclient = new DefaultHttpClient();

String getParameters = "";
try {
getParameters = URLEncoder.encode(identification, "UTF-8")
+ "/calendar.xml?apikey=" + URLEncoder.encode(API_KEY, "UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

String url = SONGKICK_URL + getParameters;
// Prepare a request object
HttpGet httpget = new HttpGet(url);

// Execute the request
HttpResponse response;


These methods worked for obtaining the bands name in an initial search. How could this be changed to perform a search for tour information with an argument retrieved from a ListView? Is this different from getting a search query from an EditText field? I didn't think there would be much of a difference. I have tried to include the affected code. I am not sure how much code I should provide.



.

stackoverflow.comm

Wednesday, April 17, 2013

[android help] Android - Using Custom Font

Android - Using Custom Font - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I applied a custom font to a TextView, but it doesn't seems to change the typeface.


Here is my code:



Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/myFont.ttf");
TextView myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setTypeface(myTypeface);


Can anyone please get me out of this issue?





























benvd is right. Don't use a fonts subdirectory.


On Mobiletuts+ there is very good tutorial on Text formatting for Android. Quick Tip: Customize Android Fonts


EDIT: Tested it myself now. Here is the solution. You can use a subfolder called fonts but it must go in the assets folder not the res folder. So



assets/fonts



Also make sure that the font ending I mean the ending of the font file itself is all lower case. In other words it should not be myFont.TTF but myFont.ttf


























I've successfully used this before. The only difference between our implementations is that I wasn't using a subfolder in assets. Not sure if that will change anything, though.






















when i have been wrote this code to set my font it dosn't work when i'm start my application suddenly my application is stop..




















default






.

stackoverflow.comm

Sunday, March 31, 2013

instantiation of FragmentTransaction object not possble according to the compiler, Android


when I try to instantiate FragmentTransaction() I the the error message:


"can not instantiate the type FragmentTransaction"


in google Android reference it states:


Public Constructors


FragmentTransaction()


so if there is a constructor of FragmentTransaction() then it must be possible to do this,



FragmentTransaction fragtransaction = new FragmentTransaction();


the question is WHY is this not possible?



.

forums.androidcentral.com

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...