Search Results

Search found 135 results on 6 pages for 'layoutparams'.

Page 1/6 | 1 2 3 4 5 6  | Next Page >

  • Logcat error: "addView(View, LayoutParams) is not supported in AdapterView" in a ListView

    - by HacKreatorz
    I'm doing an aplication for Android and something I need is that it shows a list of all files and directories in the SD Card and it has to be able to move through the different directories. I found a good tutorial in anddev: http://bit.ly/h4GyFC I modified a few things so the aplication moves in the SD Card and not in Android root Directories but the rest is mostly the same. This is my xml file for the activity: <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" /> </ListView> And this is the code for the Activity: import hackreatorz.cifrador.R; import java.io.File; import java.util.ArrayList; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class ArchivosSD extends ListActivity { private ArrayList<String> directoryEntries = new ArrayList<String>(); private File currentDirectory = new File("/sdcard/"); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); browseToSD(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } private void browseToSD() { browseTo(new File("/sdcard/")); } private void upOneLevel() { if(this.currentDirectory.getParent() != null) this.browseTo(this.currentDirectory.getParentFile()); } private void browseTo(final File directory) { if (directory.isDirectory()) { this.currentDirectory = directory; fill(directory.listFiles()); } else { Toast.makeText(ArchivosSD.this, this.directoryEntries.get(this.getSelectedItemPosition()), Toast.LENGTH_SHORT).show(); } } private void fill(File[] files) { this.directoryEntries.clear(); this.directoryEntries.add(getString(R.string.current_dir)); if(this.currentDirectory.getParent() != null) this.directoryEntries.add(getString(R.string.up_one_level)); int currentPathStringLength = (int) this.currentDirectory.getAbsoluteFile().length(); for (File file : files) { this.directoryEntries.add(file.getAbsolutePath().substring(currentPathStringLength)); } setListAdapter(new ArrayAdapter<String>(this, R.layout.archivos_sd, this.directoryEntries)); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { int selectionRowID = (int) this.getSelectedItemPosition(); String selectedFileString = this.directoryEntries.get(selectionRowID); if (selectedFileString.equals(".")) { this.browseToSD(); } else if(selectedFileString.equals("..")) { this.upOneLevel(); } else { File clickedFile = null; clickedFile = new File(this.currentDirectory.getAbsolutePath() + this.directoryEntries.get(selectionRowID)); if(clickedFile != null) this.browseTo(clickedFile); } } } I don't get any errores in Eclipse, but I get a Force Close when running the aplication on my phone and when I look at Logcat I see the following: 01-01 23:30:29.858: ERROR/AndroidRuntime(14911): FATAL EXCEPTION: main *01-01 23:30:29.858: ERROR/AndroidRuntime(14911): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView* I don't have a clue what to do, I've looked up in Google and I didn't find anything and I did the same at stackoverflow. This is my first aplication in Java and for Android so I'm a real n00b and if the answer was there, I didn't understand it so I would really apreciate if you could explain what I should do to fix this error and why. Thanks for everything in advanced.

    Read the article

  • Android VideoView LinearLayout.LayoutParams

    - by Chris
    I am playing a video using VideoView in my app. When I play it on Droid with linearlayout params FILL_PARENT, FILL_PARENT, it plays well. The same params do not work well for a myTouch. What params can I use that will work well with most devices? Thanks Chris

    Read the article

  • android: two issues using Tablerow+TextView in Tablelayout

    - by Yang
    I am using Tablerow+TextView to make a simple view for blog posts and their replies. In each TableRow I put a TextView in. Now I have two issues: The text which is longer than the screen won't automatically wrap up to be multi-line. Is it by design of TableRow? I've already set tr_content.setSingleLine(false); [update] This has been addressed, I think I should change Fill_parent to be Wrap_content in textView.tr_author_time.setLayoutParams(new LayoutParams( LayoutParams.**WRAP_CONTENT**, LayoutParams.WRAP_CONTENT)); The Table won't scroll like ListView. My rows are more than the screen size. I expect the table could be scrolled down for viewing just like ListView. Is that possible? Here is my code: TableLayout tl = (TableLayout) findViewById(R.id.article_content_table); TextView tr_title = new TextView(this); TextView tr_author_time = new TextView(this); TextView tr_content = new TextView(this); TableRow tr = new TableRow(this); for(int i = 0; i < BlogPost.size(); i++){ try{ // add the author, time tr = new TableRow(this); /////////////////add author+time row BlogPost article = mBlogPost.get(i); tr_author_time = new TextView(this); tr_author_time.setText(article.author+"("+ article.post_time+")"); tr_author_time.setTextColor(getResources().getColor(R.color.black)); tr_author_time.setGravity(0x03); tr_author_time.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); tr.addView(tr_author_time); tl.addView(tr,new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); ////////////////////// then add content row tr = new TableRow(this); tr_content = new TextView(this); tr_content.setText(article.content); tr_content.setSingleLine(false); tr_content.setGravity(0x03); tr_content.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); tr.addView(tr_content); tr.setBackgroundResource(R.color.white); tl.addView(tr,new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); }

    Read the article

  • Unable to add multiple textviews into linearLayout within a loop

    - by Adam
    for(int i=0;i<object.size();i++){ FeaturedSingleEvent event = (FeaturedSingleEvent) object.get(i); images.add(event.getImage()); LinearLayout info = new LinearLayout(this); info.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); TextView title = new TextView(this); title.setText(event.getTitle()); title.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); info.addView(title); TextView by = new TextView(this); by.setText(event.getBy() + " " + event.getBy_name()); by.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); info.addView(by); TextView summary = new TextView(this); summary.setText(event.getSummary()); summary.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); info.addView(summary); layout.addView(info); if(i == 0){ info.setVisibility(View.VISIBLE); }else{ info.setVisibility(View.GONE); } } I'm attempting to have multiple LinearLayouts, only one being visible at a time, to create a slideshow. In a for loop, I create the layouts with their textViews, and set only the first one to be visible. The problem is that only one TextView seems to be displaying, ie. if everything but summary is deleted, then summary will display. As of right now, only title will display, because i'm assuming it's the first one. I'm most likely doing it wrong, so any help would be appreciated.

    Read the article

  • Android : create RelativeLayout in Onclick Button?(Get Crash)

    - by A.A
    I have an Xml that add LinearLayout and RelativeLayout in ScrollView by programmatically.When i add Text with OnclickButton for first time show me message but for 2nd time get me crash : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ScrollView android:id="@+id/scrollID" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" > </ScrollView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="true" android:orientation="horizontal" android:paddingBottom="5dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:weightSum="1" > <EditText android:id="@+id/txtInpuConversation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.5" android:hint="Text" > <requestFocus /> </EditText> <Button android:id="@+id/btnSend" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="0.5" android:text="Click" /> </LinearLayout> </LinearLayout> My code : public class MainActivity extends Activity { String Medtconversation; EditText edtconversation; TextView txtviewUser; LinearLayout rilative; RelativeLayout relativeLayout; LinearLayout firstLinearLayout; ScrollView sclView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edtconversation = (EditText) findViewById(R.id.txtInpuConversation); sclView = (ScrollView) findViewById(R.id.scrollID); Button btn = (Button) findViewById(R.id.btnSend); final Context context = this; btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Medtconversation = edtconversation.getText().toString(); txtviewUser = new TextView(MainActivity.this); txtviewUser.setText(Medtconversation); relativeLayout = new RelativeLayout(context); firstLinearLayout= new LinearLayout(context); LayoutParams LLParamsT = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); relativeLayout.setLayoutParams(LLParamsT); relativeLayout.addView(txtviewUser, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); firstLinearLayout.setOrientation(LinearLayout.VERTICAL); LayoutParams LLParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); firstLinearLayout.setLayoutParams(LLParams); firstLinearLayout.addView(relativeLayout); Crash here now======>sclView.addView(firstLinearLayout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); edtconversation.setText(""); } }); } } I need that when i click on Button and send message for 2nd time create a new RelativeLayout in LinearLayout for show.(In scrollView) Error : AndroidRuntime MainActivity$1.onClick(MainActivity.java:54)

    Read the article

  • NullPointerException on TextView

    - by Stephen Adipradhana
    i get a null pointer exception and the program crash on each time i want to update the highscore text using setText(). what causes this problem? this code is when i set my layout, the layout is a part of the gameView using opengl, and i put the highscore textview on the upper left corner public void onCreate(Bundle savedInstanceState) { SFEngine.display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();//ambl ukuran width height layar super.onCreate(savedInstanceState); gameView = new SFGameView(this); gameView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); RelativeLayout layout = new RelativeLayout(this); layout.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); TextView textBox = new TextView(this); textBox.setId(1); textBox.setText("HIGH SCORE"); textBox.setBackgroundColor(Color.BLUE); textBox.setWidth(SFEngine.display.getWidth()/2); textBox.setHeight(50); Button pauseButton = new Button(this); pauseButton.setText("PAUSE"); pauseButton.setHeight(50); pauseButton.setWidth(SFEngine.display.getWidth()/2); pauseButton.setOnTouchListener(new OnTouchListener(){ public boolean onTouch(View v, MotionEvent e) { //pause game SFEngine.isPlaying = false; Intent i1 = new Intent(SFGames.this, pause.class); gameView.onPause(); startActivityForResult(i1,0);//hrs pk result soalny mw blk lg return true; } }); RelativeLayout.LayoutParams lp_pause = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams lp_hs = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp_hs.addRule(RelativeLayout.ALIGN_PARENT_LEFT); lp_pause.addRule(RelativeLayout.ALIGN_PARENT_TOP); lp_pause.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); textBox.setLayoutParams(lp_hs); pauseButton.setLayoutParams(lp_pause); layout.addView(gameView); layout.addView(textBox); layout.addView(pauseButton); setContentView(layout); and here is the setText code public boolean onTouchEvent (MotionEvent event){//buat nerima input user if(!SFEngine.isPlaying){ finish(); } textBox.setText("High Score :" + SFEngine.score);//here is the source of the prob .....

    Read the article

  • Animation not start immediately when the target view is out of window

    - by funnything
    Hi. When I apply some animation to the view, which is out of window, the animation not start immediately. And then, I scroll the screen to show the animation target view, the animation will start. I hope to the animation will start immediately when it apply. Any ideas? Bellow is sample code. Thank you. public class AnimationValidationActivity extends Activity { private ViewSwitcher _viewSwitcher; private Button _button; /** * utility method for animation */ private Animation buildTranslateAnimation( float fromXDelta , float toXDelta , float fromYDelta , float toYDelta ) { Animation ret = new TranslateAnimation( fromXDelta , toXDelta , fromYDelta , toYDelta ); ret.setDuration( 1000 ); return ret; } /** * build view in place of layout.xml */ private View buildView() { ScrollView ret = new ScrollView( this ); ret.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT , LinearLayout.LayoutParams.WRAP_CONTENT ) ); LinearLayout parent = new LinearLayout( this ); parent.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT , LinearLayout.LayoutParams.WRAP_CONTENT ) ); parent.setOrientation( LinearLayout.VERTICAL ); ret.addView( parent ); _viewSwitcher = new ViewSwitcher( this ); _viewSwitcher.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT , 100 ) ); parent.addView( _viewSwitcher ); View spacer = new View( this ); spacer.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT , getWindow() .getWindowManager().getDefaultDisplay().getHeight() ) ); parent.addView( spacer ); _button = new Button( this ); _button.setText( "button" ); parent.addView( _button ); return ret; } @Override public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView( buildView() ); _viewSwitcher.setFactory( new ViewSwitcher.ViewFactory() { @Override public View makeView() { TextView view = new TextView( AnimationValidationActivity.this ); view.setLayoutParams( new ViewSwitcher.LayoutParams( ViewSwitcher.LayoutParams.FILL_PARENT , ViewSwitcher.LayoutParams.FILL_PARENT ) ); view.setBackgroundColor( 0xffffffff ); view.setText( "foobar" ); return view; } } ); _button.setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { _viewSwitcher.setInAnimation( buildTranslateAnimation( _viewSwitcher.getWidth() , 0 , 0 , 0 ) ); _viewSwitcher.setOutAnimation( buildTranslateAnimation( 0 , - _viewSwitcher.getWidth() , 0 , 0 ) ); int color = new Random().nextInt(); _viewSwitcher.getNextView().setBackgroundColor( 0xff000000 | color & 0xffffff ); _viewSwitcher.showNext(); } } ); } }

    Read the article

  • Soft keyboard "del" key fails in EditText on Gallery widget

    - by droidful
    Hi, I am developing an application in Eclipse build ID 20090920-1017 using android SDK 2.2 and testing on a Google Nexus One. For the purposes of the tests below I am using the IME "Android keyboard" on a non-rooted phone. I have an EditText widget which exhibits some very strange behavior. I can type text, and then press the "del" key to delete that text; but after I enter a 'space' character, the "del" key will no longer remove characters before that space character. An example speaks a thousand words, so consider the following two incredibly simple applications... Example 1: An EditText in a LinearLayout widget: package com.example.linear.edit; import android.app.Activity; import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.widget.EditText; import android.widget.Gallery; import android.widget.LinearLayout; public class LinearEdit extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(getApplicationContext()); layout.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.MATCH_PARENT)); EditText edit = new EditText(getApplicationContext()); layout.addView(edit, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); setContentView(layout); } } Run the above application, enter text "edit example", then press the "del" key several times until the entire sentence is deleted. Everything Works fine. Now consider example 2: An EditText in a Gallery widget: package com.example.gallery.edit; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Gallery; import android.widget.LinearLayout; public class GalleryEdit extends Activity { private final String[] galleryData = {"string1", "string2", "string3"}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Gallery gallery = new Gallery(getApplicationContext()); gallery.setAdapter(new ArrayAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, galleryData) { @Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout layout = new LinearLayout(getApplicationContext()); layout.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.MATCH_PARENT)); EditText edit = new EditText(getApplicationContext()); layout.addView(edit, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); return layout; } }); setContentView(gallery); } } Run the above application, enter text "edit example", then press the "del" key several times. If you are getting the same problem as me then you will find that you can't deleted past the 'space' character. All is not well. If anyone could shed some light on this issue I would be most appreciative. Regards

    Read the article

  • ImageView doesn't rescale Image to selected size

    - by Buni
    I'm using a ImageView with a fixed size for adding an icon to a menu. In my application, I use it a lot of times, but on this ImageView the Layout Params seem to not work. Unlike the others ImageViews, in this case, I'm using a template directly, but I think that's not the problem. <?xml version="1.0" encoding="utf-8"?> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="1dp" android:layout_height="1dp" android:scaleType="fitCenter" android:src="@drawable/ic_menu_moreoverflow_normal_holo_dark" android:contentDescription="ICON" /> Its been used in code as follows. ImageView iview =(ImageView) View.inflate(context, R.layout.icon, null); Theoretically, It should resize automatically the image, however, the images continues with the original size, although the size was 1dp. Where is the problem? Thanks a lot!

    Read the article

  • Create ImageButton programatically depending on local database records

    - by user2507920
    As i described in title, i have a local db in sqlite. I want to create ImageButton parametrically. How many times is local database loop executing? Please see code below : RelativeLayout outerRelativeLayout = (RelativeLayout)findViewById(R.id.relativeLayout2_making_dynamically); db.open(); Cursor c = db.getAllLocal_Job_Data(); if(c!=null){ if(c.moveToFirst()){ do { RelativeLayout innerRelativeLayout = new RelativeLayout(CalendarActivity.this); innerRelativeLayout.setGravity(Gravity.CENTER); ImageButton imgBtn = new ImageButton(CalendarActivity.this); imgBtn.setBackgroundResource(R.drawable.color_001); RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); imgBtn.setLayoutParams(imageViewParams); // Adding the textView to the inner RelativeLayout as a child innerRelativeLayout.addView(imgBtn, new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); outerRelativeLayout.addView(innerRelativeLayout, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } while (c.moveToNext()); } } db.close(); But when i run the project, i can see only one button created there. I think there are many buttons but here image button is creating on last created image button. I think i should use android:layout_toRightOf with previous created button but i cant find how to place it here. I have tried some ideas but it did not change any thing. So please anybody has any idea to solve my problem then please share it with me.

    Read the article

  • How to set padding to columns in table layout dynamically

    - by Praveenb
    Hi all, I am trying to create a table layout with buttons dynamically. I am able to get the table layout with buttons. bt i need padding between buttons. How i can get programatically. I tried following code bt private void showCowsTblField() { for (int row = 0; row < numberOfRowsInField-1; row++) { TableRow tableRow = new TableRow(this); tableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT )); for (int column = 0; column < numberOfColumnsInField -1; column++) { blocks[row][column].setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); blocks[row][column].setPadding(blockPadding, blockPadding, blockPadding, blockPadding); tableRow.addView(blocks[row][column]); tableRow.setPadding(blockPadding, blockPadding, blockPadding, blockPadding); } tblCows.addView(tableRow,new TableLayout.LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); } } Please let me know.... Thanks.

    Read the article

  • Can't get Dialog hosting a WebView to layout properly

    - by user246114
    Hi, I'm trying to host a webview on a dialog, without a titlebar, but I'm getting odd layout results. Example test: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); LinearLayout ll = new LinearLayout(getContext()); ll.setOrientation(LinearLayout.VERTICAL); ll.setLayoutParams(new LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); ll.setMinimumWidth(display.getWidth() - 10); ll.setMinimumHeight(display.getHeight() - 10); WebView wv = new WebView(getContext()); wv.setLayoutParams(new LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); wv.getSettings().setJavaScriptEnabled(true); ll.addView(mWebView); setContentView(ll, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); } the dialog is inflated at startup, but the webview is not visible. If I rotate the device, it becomes visible, and fills the whole parent layout as requested. What is the right way to do this? I simply want a dialog which occupies most of the device screen, and has a WebView on it which fills the entire space. Thanks

    Read the article

  • Android: Get the X and Y coordinates of a TextView?

    - by Jep Knopz
    I am working now on a project. I have 2 draggable textView in a circle. I want to add those value inside the circle when the circle is drag over the other circle. the first option that I have is to get the X and Y of the circle, but I get it. Can anyone fix my code? Here is the Code: MainActivity public class MainActivity extends Activity { int windowwidth; int windowheight; TextView bola; TextView bola2; private float x; private float y; private android.widget.RelativeLayout.LayoutParams layoutParams; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); windowwidth = getWindowManager().getDefaultDisplay().getWidth(); windowheight = getWindowManager().getDefaultDisplay().getHeight(); bola = (TextView) findViewById(R.id.ball); bola2 = (TextView) findViewById(R.id.ball2); bola2.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub layoutParams = (RelativeLayout.LayoutParams) bola2 .getLayoutParams(); switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: int x_cord = (int) event.getRawX(); int y_cord = (int) event.getRawY(); if (x_cord > windowwidth) { x_cord = windowwidth; } if (y_cord > windowheight) { y_cord = windowheight; } layoutParams.leftMargin = x_cord - 25; layoutParams.topMargin = y_cord - 75; bola2.setLayoutParams(layoutParams); break; default: break; } return true; } }); bola.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { layoutParams = (RelativeLayout.LayoutParams) bola .getLayoutParams(); switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: int x_cord = (int) event.getRawX(); int y_cord = (int) event.getRawY(); if (x_cord > windowwidth) { x_cord = windowwidth; } if (y_cord > windowheight) { y_cord = windowheight; } layoutParams.leftMargin = x_cord - 25; layoutParams.topMargin = y_cord - 75; bola.setLayoutParams(layoutParams); break; default: break; } // TODO Auto-generated method stub return true; } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; }} Activity_main.xml <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" > <TextView android:id= "@+id/ball" android:background="@drawable/bgshape" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1" tools:context=".MainActivity" /> <TextView android:id= "@+id/ball2" android:background="@drawable/bgshape" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2" tools:context=".MainActivity" android:layout_x="60dp" android:layout_y="20dp" /> The bgshape.xml(for the circle) <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <padding android:bottom="20dp" android:left="25dp" android:right="25dp" android:top="20dp" /> <stroke android:width="2dp" android:color="#000000" /> <solid android:color="#ffffff" /> <corners android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp" android:topLeftRadius="30dp" android:topRightRadius="30dp" /> This code works well. Could anyone fix this so that I can add the value inside the circle when they hit each other?

    Read the article

  • Set margins in a LinearLayout programmatically.

    - by Timmmm
    I'm trying to use Java (not XML) to create a LinearLayout with buttons that fill the screen, and have margins. Here is code that works without margins: LinearLayout buttonsView = new LinearLayout(this); buttonsView.setOrientation(LinearLayout.VERTICAL); for (int r = 0; r < 6; ++r) { Button btn = new Button(this); btn.setText("A"); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); // Verbose! lp.weight = 1.0f; // This is critical. Doesn't work without it. buttonsView.addView(btn, lp); } ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); setContentView(buttonsView, lp); So that works fine, but how on earth do you give the buttons margins so there is space between them? I tried using LinearLayout.MarginLayoutParams, but that has no weight member so it's no good. And it doesn't work if you pass it lp in its constructor either. Is this impossible? Because it sure looks it, and it wouldn't be the first Android layout task you can only do in XML.

    Read the article

  • Android Google map balloon over overlayitem

    - by Faisal khan
    I am using google map, displaying overlayitems on the google map. To create balloon effect, i am using customize view and using geopoints with MapView.LayoutParams to display it at particular location. overlayitem's icon and baloon both having same geopoint thats why they both are overriding eatch other. I want to display baloon over the overlayitem icon look like it should point to the icon. Follwing is my code MapView.LayoutParams mapParams = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT, mapEvent.getGeoPoint(), MapView.LayoutParams.BOTTOM_CENTER); I want to display baloon like following please tell me should i decrease lat long to make it top ? or should i change the layout param.Bottom or what i tried different variation not working like following

    Read the article

  • alertDialog.getButton() method gives null pointer exception android

    - by Are
    Hi, Iam planing to give create 3 buttons with layout_weight=1, not interested in custom dialog.So I have written below code.It is not working.Always yes button gives me null. Whats wrong in this code? AlertDialog dialog= new AlertDialog.Builder(this).create(); dialog.setIcon(R.drawable.alert_icon); dialog.setTitle("title"); dialog.setMessage("Message"); dialog.setButton(AlertDialog.BUTTON_POSITIVE,"Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); Button yesButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); Log.w("Button",""+yesButton);//here getting null LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f); yesButton.setLayoutParams(layoutParams); dialog.show(); Regards, Android developer.

    Read the article

  • how to set layout_weight programmatically for alert dialog button?

    - by Are
    Hi, Iam planing to give create 3 buttons with layout_weight=1, not interested in custom dialog.So I have written below code.It is not working.Always yes button gives me null. Whats wrong in this code? AlertDialog dialog= new AlertDialog.Builder(this).create(); dialog.setIcon(R.drawable.alert_icon); dialog.setTitle("title"); dialog.setMessage("Message"); dialog.setButton(AlertDialog.BUTTON_POSITIVE,"Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); Button yesButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); Log.w("Button",""+yesButton);//here getting null LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f); yesButton.setLayoutParams(layoutParams); dialog.show(); Regards, Android developer.

    Read the article

  • Why is my custom view not appearing?

    - by user351469
    When I comment out setContentView(boardView); in my Game.java my custom view in BoardView works fine and displays everything nicely... but onSizeChanged never gets called in BoardView.java... so I can't read the device width and height at runtime. If I leave setContentView uncommented onSizeChanged works... but the screen is blank! I want to be able to read the screen width and height at runtime and set the sizes of my ImageViews at creation so they are the optimal size. public class Game extends Activity implements OnClickListener{ private BoardView boardView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); boardView = new BoardView(this); setContentView(boardView); // when this line disabled, it looks ok boardView.requestFocus(); } public class BoardView extends View { private final Game game; private float width; // width of one unit private float height; // height of one unit public BoardView(Context context){ super(context); this.game = (Game)context; setFocusable(true); setFocusableInTouchMode(true); LinearLayout maincontainer = new LinearLayout(game); maincontainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); maincontainer.setGravity(Gravity.CENTER); maincontainer.setOrientation(LinearLayout.VERTICAL); maincontainer.setBackgroundColor(Color.BLACK); LinearLayout innercontainer = new LinearLayout(game); innercontainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); innercontainer.setGravity(Gravity.CENTER); innercontainer.setOrientation(LinearLayout.HORIZONTAL); // declare a new table TableLayout layout = new TableLayout(game); layout.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); // build a grid of ImageViews in a TableLayout for (int f=1; f<=7; f++) { TableRow tr = new TableRow(game); for (int c=1; c<=7; c++) { ImageView b = new ImageView(game); b.setImageResource(R.drawable.neworb); b.setOnClickListener(game); tr.addView(b, 30,30); // I'd like to not use fixed values here } // for layout.addView(tr); } // for innercontainer.addView(layout); maincontainer.addView(innercontainer); game.setContentView(maincontainer); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh){ width = w/9f; height = width; super.onSizeChanged(w, h, oldw, oldh); } }

    Read the article

  • Android: How to get text of dynamically created radio button selected by the user?

    - by Maxood
    How can i retrieve the text of a dynamically created radio button selected by the user? Here's my code: RadioGroup radiogroup = (RadioGroup) findViewById(R.id.rdbGp1); // layout params to use when adding each radio button LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams( RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT); for (int i = 0; i < 4; i++){ final RadioButton newRadioButton = new RadioButton(this); c3 = db.getAns(3); for (int j=0;j<i;j++) c3.moveToNext(); label = c3.getString(0); newRadioButton.setText(label); newRadioButton.setId(6); radiogroup.addView(newRadioButton, layoutParams); Waiting for the reply, Maqsood

    Read the article

  • Dynmically added row in TableLayout

    - by Balaji
    This is my activity class i want to add one textview to TableRow but i cannot show the textview in TableLayout. Activity import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup.LayoutParams; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; import android.widget.LinearLayout; public class TableRunTime extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TableLayout tl = (TableLayout) findViewById(R.id.arcitle_content_table); TextView txt = new TextView(this); TableRow tr = new TableRow(this); txt.setText("Book Name"); txt.setTextColor(Color.WHITE); txt.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); tr.addView(txt); tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } } This is manifest file any one help how to show textview in TableLayout

    Read the article

  • how to center layout to vertical in android through java code?

    - by UMMA
    friends, i want to set android:layout_centerVertical="true" property of layout through java code of an image. can any one guide me how to achieve this. here is my code. RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.height = (int)totalHeight; img.setLayoutParams(params); i have tried using setScaleType(ScaleType.FIT_CENTER) but no use. any help would be appriciated.

    Read the article

  • dynamically add imagebutton programatically android

    - by user1266179
    I am getting dynamic length of the string array and i want to display images in the imagebutton and that too in horizontal view as i had added button but it shows in the vertical layout.Please help. This is my code: for (int i =0;i<adapt_objmenu.image_array.length;i++){ ImageButton b1 = new ImageButton(myrefmenu); b1.setId(100 + i); // b1.setText(adapt_objmenu.city_name_array[i]); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (i > 0) { lp.addRule(RelativeLayout.BELOW, b1.getId() - 1); } b1.setLayoutParams(lp); relative.addView(b1); //relate.addView(b1, i, new RelativeLayout.LayoutParams(width,height)); //height = height+80; }

    Read the article

  • Using AdMob with Games that use Open GLES

    - by Vishal Kumar
    Can anyone help me integrating Admob to my game. I've used the badlogic framework by MarioZencher ... and My game is like the SuperJumper. I am unable to use AdMob after a lot of my attempts. I am new to android dev...please help me..I went thru a number of tutorials but not getting adds displayed ... I did the following... get the libraries and placed them properly My main.xml looks like this android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" / My Activity class onCreate method: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout layout = new RelativeLayout(this); adView = new AdView(this, AdSize.BANNER, "a1518637fe542a2"); AdRequest request = new AdRequest(); request.addTestDevice(AdRequest.TEST_EMULATOR); request.addTestDevice("D77E32324019F80A2CECEAAAAAAAAA"); adView.loadAd(request); layout.addView(glView); RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); adParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(adView, adParams); setContentView(layout); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); glView = new GLSurfaceView(this); glView.setRenderer(this); //setContentView(glView); glGraphics = new GLGraphics(glView); fileIO = new AndroidFileIO(getAssets()); audio = new AndroidAudio(this); input = new AndroidInput(this, glView, 1, 1); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame"); } My Manifest file looks like this .... <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|smallestScreenSize"/> </application> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-sdk android:minSdkVersion="7" /> When I first decided to use the XML for admob purpose ..it showed no changes..it even didn't log the device id in Logcat... Later when I wrote code in the Main Activity class.. and run ... Application crashed ... with 7 errors evry time ... The android:configChanges value of the com.google.ads.AdActivity must include screenLayout. The android:configChanges value of the com.google.ads.AdActivity must include uiMode. The android:configChanges value of the com.google.ads.AdActivity must include screenSize. The android:configChanges value of the com.google.ads.AdActivity must include smallestScreenSize. You must have AdActivity declared in AndroidManifest.xml with configChanges. You must have INTERNET and ACCESS_NETWORK_STATE permissions in AndroidManifest.xml. Please help me by telling what wrong is there with the code? Can I write code only in xml files without changing the Activity class ... I will be very grateful to anyone providing support.

    Read the article

  • Help with Android LinearLayout or RelativeLayout

    - by PeEll
    I need to create two views programmatically (because I need to access the ondraw of one of the views). For some reason, no matter what I do to add the views to the contentview, they don't show up vertically stacked, one below the other. I can do it just fine using the XML using a RelativeLayout and layout positioning, but with the XML I can't create a view object and overload the ondraw method. What am I doing wrong with the programmatic approach, and how do I solve this problem? LinearLayout mLinearLayout; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a LinearLayout in which to add the ImageView mLinearLayout = new LinearLayout(this); TextView tv = new TextView(this); tv.setBackgroundColor(0xff333333); tv.setText("Enter your member number:"); tv.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); DrawableView i = new DrawableView(this); i.layout(0,40,0,0); i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mLinearLayout.addView(tv); mLinearLayout.addView(i,300,300); setContentView(mLinearLayout); }

    Read the article

  • Creating Linear Layout with TextViews using a for loop

    - by cad8
    Hi all, I was wondering if there is a way to dynamically create an additional linear layout with a textview within a predefined liner layout. THis is my code so you get the gist of what I am asking: LinearLayout MainLL= (LinearLayout) findViewById(R.id.myLayoutId); for(int i=0; i<5; i++) { LinearLayout childLL= new LinearLayout(this); childLL.setOrientation(LinearLayout.VERTICAL); childLL.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); childLL.setGravity(Gravity.LEFT); TextView text = new TextView(this); text.setText("The Value of i is :"i); text.setTextSize(12); text.setGravity(Gravity.LEFT); text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); childLL.addView(text); MainLL.addView(childLL); } My problem is that I am only getting "The Value of i is :0" as the output, i.e. the first instance. Any help would be much appreciated

    Read the article

1 2 3 4 5 6  | Next Page >