I am developing android application in which i have 12 Dynamic Frame layout in which Frame layout having Text view,video,and play/pause button over it .I want to fetch text in the Text view field by JSON. But my problem is that when i fetch text in Text view field using JSON text will appear in 12th frame and rest of 11 frame are empty.I don't know how to resolve this .kindly help me .
public class MainActivity extends Activity {
String moviename;
private ProgressDialog pDialog;
VideoView vv;
TextView showingat, movie;
FrameLayout frame;
ArrayList<String> abc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigationbar);
abc = new ArrayList<>();
new Theaterflow().execute();
//Main Relative layout.
final RelativeLayout rl = (RelativeLayout)findViewById(R.id.MainRelativeLayout);
//Main Scrollview.
final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
//Main Linearlayout.
final LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout1);
//Dynamically creation of Layouts.
FrameLayout.LayoutParams playpausebtn = new FrameLayout.LayoutParams(70, 70);
FrameLayout.LayoutParams sound = new FrameLayout.LayoutParams(55, 35);
FrameLayout.LayoutParams nowshwingat = new FrameLayout.LayoutParams(200, 60);
FrameLayout.LayoutParams movie_name = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 60);
//Defining array for framelayout.
ArrayList fHolder = new ArrayList();
int l = 12;
for (int i = 0; i<=l; i++) {
//Dynamically frameslayout for video
fHolder.add(frame);
frame = new FrameLayout(this);
FrameLayout.LayoutParams frameparams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 350);
frameparams.setMargins(0, 2, 0, 0);
frame.setId(i + 1);
frame.setMinimumHeight(350);
ll.addView(frame);
// Video over frames
vv = new VideoView(this);
vv.setId(i + 1);
vv.setLayoutParams(frameparams);
vv.setMinimumHeight(350);
frame.addView(vv);
//Pause btn over video
Button pausebtn = new Button(this);
pausebtn.setId(i + 1);
pausebtn.setBackgroundResource(R.drawable.pause);
pausebtn.setLayoutParams(playpausebtn);
playpausebtn.gravity = Gravity.CENTER;
frame.addView(pausebtn);
//Play btn over video
Button playbtn = new Button(this);
playbtn.setLayoutParams(playpausebtn);
playbtn.setId(i + 1);
playbtn.setBackgroundResource(R.drawable.playy);
playpausebtn.gravity = Gravity.CENTER;
frame.addView(playbtn);
//Sound btn over video
Button soundbtn = new Button(this);
soundbtn.setLayoutParams(sound);
soundbtn.setId(i + 1);
soundbtn.setBackgroundResource(R.drawable.sound);
sound.setMargins(0, 15, 5, 0);
sound.gravity = Gravity.RIGHT;
frame.addView(soundbtn);
//now showing at over video
showingat = new TextView(this);
showingat.setLayoutParams(nowshwingat);
showingat.setText("Now showing at ");
showingat.setTextSize(15);
showingat.setTextColor(getResources().getColor(R.color.white));
nowshwingat.setMargins(10, 0, 0, 0);
nowshwingat.gravity = Gravity.LEFT | Gravity.BOTTOM;
frame.addView(showingat);
movie = new TextView(MainActivity.this);
movie.setLayoutParams(movie_name);
movie.setId(i+1);
movie.setText(" ");
movie.setTextSize(15);
movie.setTextColor(getResources().getColor(R.color.white));
movie_name.setMargins(10, 10, 0, 0);
movie_name.gravity = Gravity.TOP | Gravity.LEFT;
frame.addView(movie);
}
}
private class Theaterflow extends AsyncTask<String, Void, String> {
// URL to get contents JSON
String url = "http://filfest.in/demo/theater/first-theater-data.php";
JSONArray contents = null;
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Loading Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected String doInBackground(String...urls){
ArrayList arraylist = new ArrayList<HashMap<String, String>>();
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonstr = sh.makeServiceCall(url, null);
if (jsonstr != null) {
try {
JSONObject jObject1 = new JSONObject(jsonstr);
contents = jObject1.optJSONArray("contents");
for (int i = 0; i < contents.length(); i++) {
JSONObject c1 = contents.getJSONObject(i);
moviename = c1.getString("movie_name");
abc.add(moviename);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
public void onPostExecute(String result) {
if (pDialog.isShowing())
pDialog.dismiss();
for (int i=0;i<abc.size();i++)
{
movie.setText(moviename);
}
}
}
}
Add view Programatically in LinearLayout:
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llParent"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Activity.java:
LinearLayout llParent = (LinearLayout)findViewById(R.id.llParent);
onPostExecute() of AsyncTask:
for (int i=0;i<Your_ArrayList.size(); i++){
TextView txtView = new TextView(this);
txtView.setText(Your_ArrayList.get(i).getMovieName());
llParent.addView(txtView);
}
Edit:
llParent.invalidate();
Hope this will help you.
inside your for loop
movie = new TextView(MainActivity.this);
movie.setTag(i);
insid your onPost() for loop
final int childCount = ll.getChildCount();
for (int y = 0; y < childCount; y++) {
final View child = ll.getChildAt(y);
if (child instanceof FrameLayout) {
int childs = ((FrameLayout) child).getChildCount();
for (int j = 0; j < childs; j++) {
final View childViews = ((ViewGroup) child)
.getChildAt(j);
if (childViews instanceof TextView) {
final Object tagObj = childViews.getTag();
if (tagObj != null && tagObj.equals(i)) {
((TextView) childViews).setText("Movie "
+ i);
}
}
}
}
}
Related
I want to setText on Button, with the text I get from json parse, and set it into Button Array. I wonder to set via looping. Can anyone help me?
for(int i = 0; i < jumlah_table; i++) {
JSONObject object = jsonArray.getJSONObject(i);
final String nama[] = new String[jumlah_table];
nama[i] = object.getString("table_name");
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
int j = 0;
buttons[j].setText(nama[j]);
j++;
}
});
}
Thanks for your help.
try this: initialize your array outside:
final String nama[] = new String[jumlah_table];
Now in Asynch task onPostExecute use the following code;
for (int i = 0; i < jumlah_table; i++) {
JSONObject object = jsonArray.getJSONObject(i);
nama[i] = object.getString("table_name");
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
Button btn = new Button(this);
btn.setId(i);
final int id_ = btn.getId();
btn.setText(nama[i]);
linear.addView(btn, params);
}
where
LinearLayout linear = (LinearLayout)findViewById(R.id.your_layout);
Here, I guess this is what you want:
for(int i = 0; i < jumlah_table; i++) {
JSONObject object = jsonArray.getJSONObject(i);
final String nama[] = new String[jumlah_table];
nama[i] = object.getString("table_name");
int j = i;
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
buttons[j].setText(nama[j]);
}
});
}
How can I refresh the LinearLayout called "contNoticias" after doing a click in a button?
Here is my code:
contNoticias = (LinearLayout)findViewById(R.id.contNoticias);
int arrayNoticias = 1;
for (int i = 0; i < arrayNoticias; i++) {
//agregar views
RelativeLayout relativeLayout = new RelativeLayout(antro.this);
relativeLayout.setPadding(0, 0, 0, 0);
relativeLayout.setId(+1);
contNoticias.addView(relativeLayout);
relativeLayout.setBackgroundResource(R.drawable.textviews_menu);
//Separar variables
try {
httpHandler handler = new httpHandler();
String response = handler.post(url + "MyDayFiles/muro.php");
JSONArray array = new JSONArray(response);
for (int u = 0; u < array.length(); u++) {
JSONObject jsonObject = array.getJSONObject(u);
tituloN += jsonObject.getString("nombre") + "/";
tituloN = tituloN.replace("null", "");
titulosN = tituloN.split("/");
noticiaN += jsonObject.getString("noticia") + "/";
noticiaN = noticiaN.replace("null", "");
noticiasN = noticiaN.split("/");
imagenN += jsonObject.getString("foto") + "/";
imagenN = imagenN.replace("null", "");
imagenesN = imagenN.split("/");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//imagen
ImageView imagenNoticia = new ImageView(antro.this);
imagenNoticia.setId(+2);
RelativeLayout.LayoutParams imagenNoticiaParams = new RelativeLayout.LayoutParams(250, 250);
imagenNoticiaParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
imagenNoticiaParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
imagenNoticiaParams.addRule(RelativeLayout.ALIGN_PARENT_START);
imagenNoticia.setLayoutParams(imagenNoticiaParams);
imagenNoticia.setScaleType(ImageView.ScaleType.CENTER_CROP);
Picasso.with(this).load(url + "MyDayFiles/imgnoticias/" + imagenesN[i]).into(imagenNoticia);
//imagen
//titulo
TextView tituloNoticia = new TextView(antro.this);
tituloNoticia.setId(+3);
RelativeLayout.LayoutParams tituloNoticiaParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
tituloNoticiaParams.addRule(RelativeLayout.RIGHT_OF, imagenNoticia.getId());
tituloNoticia.setLayoutParams(tituloNoticiaParams);
tituloNoticia.setTextColor(Color.DKGRAY);
tituloNoticia.setTextSize(12);
tituloNoticia.setPadding(20, 0, 0, 0);
tituloNoticia.setText(titulosN[i]);
//titulo
//noticia
TextView textoNoticia = new TextView(antro.this);
textoNoticia.setId(+4);
RelativeLayout.LayoutParams textoNoticiaParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
textoNoticiaParams.addRule(RelativeLayout.BELOW, tituloNoticia.getId());
textoNoticiaParams.addRule(RelativeLayout.RIGHT_OF, imagenNoticia.getId());
textoNoticia.setLayoutParams(textoNoticiaParams);
textoNoticia.setTextColor(Color.GRAY);
textoNoticia.setTextSize(12);
textoNoticia.setPadding(20, 0, 0, 0);
textoNoticia.setText(noticiasN[i]);
//noticia
//agregar views
relativeLayout.addView(imagenNoticia);
relativeLayout.addView(tituloNoticia);
relativeLayout.addView(textoNoticia);
}
The thing is I want to refresh the views inside my LinearLayout when the user clicks a button "Post" so the new post can be displayed at the screen at the moment the user clicks the button
I'm having an error on loading the image from the server and displaying it using the Picasso library, I have a JSON string and it has a field of "img" => "whateverimageofanarticle.jpg", where in the value of that column on a JSON String may vary according to the content of the database. I can get the imagepath given by the JSON string, and display it on a textview but when I place it on the parameter of the .load() method in the Picasso Library, it does not work and stopped the execution of my app :(
Anyway, I'm using fragments instead of library for easier and faster execution of the application (I don't know if fragments matters on my problem), also the code is in the postExecute method of the asynctask, where in the onPostExecute() was overriden. Here is my exact code and my whole code.
ImageView banner = new ImageView(getActivity().getApplicationContext());
banner.getLayoutParams().height = 50;
banner.getLayoutParams().width = 80;
banner.requestLayout();
Picasso.with(getActivity().getApplicationContext())
.load("http://rtu-astronet.com/emag/"+_jsonObject.optString("img").toString())
.into(banner);
Whole code:
public class CollegeBulletinListFragment extends Fragment implements OnClickListener, Connector.OnPostExecuteListener{
public CollegeBulletinListFragment(){
}
TextView kem;
TextView headlinehead;
TextView shortdesc;
TextView headlinesender;
LinearLayout llist;
ImageButton img;
ProgressBar pbColBul;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_collegebulletinlist, container, false);
kem = (TextView) rootView.findViewById(R.id.mon_title);
img = (ImageButton) rootView.findViewById(R.id.imageButton1);
pbColBul = (ProgressBar) rootView.findViewById(R.id.pBcollegebul);
img.setOnClickListener(this);
headlinehead = (TextView) rootView.findViewById(R.id.mon_head_title);
shortdesc = (TextView) rootView.findViewById(R.id.mon_head_desc);
headlinesender = (TextView) rootView.findViewById(R.id.mon_head_sender);
String c = getArguments().getString("passingWord");
llist = (LinearLayout) rootView.findViewById(R.id.lllist);
int colval = this.setTextAndColorsToHead(c);
pbColBul.setVisibility(ProgressBar.VISIBLE);
//Execute items on scroll view
String secondFlag = "list";
Connector connect= new Connector(getActivity().getApplicationContext(),colval,secondFlag,0,0,0,"","");
connect.setOnPostExecuteListener(this);
connect.execute("");
return rootView;
}
public int setTextAndColorsToHead(String arg){
int collegeval = 0;
if (arg.equals("GN")){
kem.setText("General News");
} else if (arg.equals("CCS")){
kem.setText("College of Computer Studies");
collegeval = 1;
} else if (arg.equals("COE")){
kem.setText("College of Engineering");
collegeval = 2;
} else if (arg.equals("COED")){
kem.setText("College of Education");
collegeval = 4;
} else if (arg.equals("CON")){
kem.setText("College of Nursing");
collegeval = 3;
} else if (arg.equals("CBA")){
kem.setText("College of Business and Accountancy");
collegeval = 5;
} else if (arg.equals("CAS")){
kem.setText("College of Arts and Sciences");
collegeval = 6;
} else if (arg.equals("CIHM")){
kem.setText("College of International and Hospitality Management");
collegeval = 7;
}
return collegeval;
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
SpecificArticleFragment spcf = new SpecificArticleFragment();
Bundle args = new Bundle();
String tag = arg0.getTag().toString();
args.putString("art_id",tag);
spcf.setArguments(args);
FragmentManager fm = getFragmentManager();
fm.beginTransaction().replace(R.id.content_frame, spcf).commit();
}
#Override
public void onPostExecute(String result) {
//headlinehead.setText(result);
try{
JSONObject jsonRootObj = new JSONObject(result);
JSONArray jsonArray = jsonRootObj.optJSONArray("Data");
JSONObject jsonObject = jsonArray.getJSONObject(0);
//code for headline
this.headlinehead.setText(jsonObject.optString("title").toString());
this.shortdesc.setText(jsonObject.optString("shortdesc").toString());
this.headlinesender.setText(jsonObject.optString("penname").toString());
this.img.setTag(jsonObject.optString("id").toString());
//code for headline
for (int p = 1; p < jsonArray.length(); p++){
JSONObject _jsonObject = jsonArray.getJSONObject(p);
LinearLayout conteach = new LinearLayout(getActivity().getApplicationContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
conteach.setLayoutParams(lp);
conteach.setOrientation(LinearLayout.VERTICAL);
ImageView banner = new ImageView(getActivity().getApplicationContext());
banner.getLayoutParams().height = 50;
banner.getLayoutParams().width = 80;
banner.requestLayout();
Picasso.with(getActivity().getApplicationContext())
.load("http://rtu-astronet.com/emag/"+_jsonObject.optString("img").toString())
.into(banner);
TextView art_title = new TextView(getActivity().getApplicationContext());
art_title.setText(_jsonObject.optString("title").toString());
art_title.setTextSize(20);
art_title.setLayoutParams(new LayoutParams(350,LayoutParams.WRAP_CONTENT));
TextView art_shortdesc = new TextView(getActivity().getApplicationContext());
art_shortdesc.setText(_jsonObject.optString("shortdesc").toString());
art_shortdesc.setTextSize(14);
art_shortdesc.setTypeface(null, Typeface.ITALIC);
art_shortdesc.setLayoutParams(new LayoutParams(350,LayoutParams.WRAP_CONTENT));
TextView art_sender = new TextView(getActivity().getApplicationContext());
art_sender.setText("Written by: " + _jsonObject.optString("sender").toString());
art_sender.setTextSize(14);
art_sender.setLayoutParams(new LayoutParams(350,LayoutParams.WRAP_CONTENT));
art_sender.setPadding(0, 0, 0, 15);
conteach.addView(art_title);
conteach.addView(art_shortdesc);
conteach.addView(art_sender);
conteach.setTag(_jsonObject.optString("id").toString());
conteach.setClickable(true);
conteach.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SpecificArticleFragment spcf = new SpecificArticleFragment();
Bundle args = new Bundle();
args.putString("art_id", v.getTag().toString());
spcf.setArguments(args);
FragmentManager ft = getFragmentManager();
ft.beginTransaction().replace(R.id.content_frame, spcf).commit();
}
});
this.llist.addView(conteach);
}
this.pbColBul.setVisibility(ProgressBar.GONE);
} catch(JSONException e){
}
}
}
Problem solved, I just change
banner.getLayoutParams().height = 50;
banner.getLayoutParams().width = 80;
banner.requestLayout();
to
banner.setLayoutParams() and set the layout width and height , also I inserted an initial image for the imageview that will going to change after the doInBackground() method
I visit so many solutions regarding this issue but can't catch it clearly .When ever I run the project first time it works perfectly but when I run it second time then it fire this error in logCat
The specified child already has a parent. You must call removeView() on the child's parent first
where is the error in that code segment ?where should I change in code. any suggestion is acceptable .Thanks in advance ..
Main.java
public class MainActivity extends Activity {
List<PieDetailsItem> piedata = new ArrayList<PieDetailsItem>(0);
EditText edt3;
Button btnChart;
public String s15;
public String[] strArray;
public ImageView mImageView ;
public LinearLayout finalLayout ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
finalLayout = (LinearLayout) findViewById(R.id.pie_container);
mImageView = new ImageView(this);
edt3 = (EditText) this.findViewById(R.id.editText1);
btnChart = (Button) findViewById(R.id.button1);
btnChart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
/*if(mImageView != null) {
finalLayout.removeView(mImageView);
}
else {*/
s15 = edt3.getText().toString();
/*System.out.println("value 1 is --->"+s10);
System.out.println("value 2 is --->"+s12);*/
System.out.println("value 3 is --->"+s15);
String domain = s15;
strArray = domain.split("\\,");
for (String str : strArray) {
System.out.println(str);
}
// }
openChart();
}
});
}
private void openChart(){
Integer[] items = new Integer[strArray.length];
//double[] distribution = new double[strArray.length];
for (int i = 0; i < items.length; i++) {
items[i] = Integer.parseInt(strArray[i]);
System.out.println("xxxxxx"+items[i]);
}
PieDetailsItem item;
int maxCount = 0;
int itemCount = 0;
// int items[] = { 20, 40, 10, 15, 5 };
int colors[] = { -6777216, -16776961, -16711681, -12303292, -7829368 };
// String itemslabel[] = { " vauesr ur 100", " vauesr ur 200",
// " vauesr ur 300", " vauesr ur 400", " vauesr ur 500" };
for (int i = 0; i < items.length; i++) {
itemCount = items[i];
item = new PieDetailsItem();
item.count = itemCount;
// item.label = itemslabel[i];
item.color = colors[i];
piedata.add(item);
maxCount = maxCount + itemCount;
}
int size = 200;
int BgColor = 0xffa11b1;
Bitmap mBaggroundImage = Bitmap.createBitmap(size, size,
Bitmap.Config.ARGB_8888);
View_PieChart piechart = new View_PieChart(this);
piechart.setLayoutParams(new LayoutParams(size, size));
piechart.setGeometry(size, size, 2, 2, 2, 2, 2130837504);
piechart.setSkinparams(BgColor);
piechart.setData(piedata, maxCount);
piechart.invalidate();
piechart.draw(new Canvas(mBaggroundImage));
piechart = null;
//ImageView mImageView = new ImageView(this);
mImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
mImageView.setBackgroundColor(BgColor);
mImageView.setImageBitmap(mBaggroundImage);
//LinearLayout finalLayout = (LinearLayout) findViewById(R.id.pie_container);
finalLayout.addView(mImageView);
}
}
You're adding mImageView to the layout multiple times. A view can only be part of 1 ViewGroup. You need to either add it only once, or create a second ImageView if you really want 2 of them in the layout.
I try to make scroll view with button, imageview and viedoview.
I create dynamically from my code.
When i put button with video, i can see the both of them. The same with button and imageView.
My problem is when there is videView and imageView. When i have both of them i cant see the VidoView and i seeo only the imageView.
Thank for helping :)
Here is my code:
XML scrollview code:
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/dateMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
</ScrollView>
my java code:
private void addPics() {
extras = getIntent().getExtras();
String s = extras.getString("date");
DataBaseMain data = new DataBaseMain(this);
data.open();
paths = data.getWorkOutPic(s);
data.close();
if(paths == null || paths.length < 1)
return;
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
for(int i = 0; i < paths.length; i++){
Bitmap yourSelectedImage = BitmapFactory.decodeFile(paths[i]);
ImageButton pic = new ImageButton(this);
pic.setImageBitmap(yourSelectedImage);
pic.setAdjustViewBounds(true);
pic.setLayoutParams(lp);
pic.setId(i);
pic.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View arg0) {
selectedPictrue = arg0.getId();
onButtonClickEvent(arg0);
return true;
}
});
linear.addView(pic);
}
}
private void addVideos() {
extras = getIntent().getExtras();
String s = extras.getString("date");
DataBaseMain data = new DataBaseMain(this);
data.open();
videos = data.getWorkOutVideo(s);
data.close();
if(videos == null || videos.length < 1)
return;
LinearLayout linear = (LinearLayout) findViewById(R.id.dateMain);
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
LayoutParams lp2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
for(int i = 0; i < videos.length; i++){
Button b = new Button(this);
b.setLayoutParams(lp2);
b.setText("Delete video");
b.setId(i+50);
linear.addView(b);
b.setOnClickListener(this);
VideoView video = new VideoView(this);
video.setVideoPath(videos[i]);
video.setLayoutParams(lp);
video.setId(i+50);
video.setMediaController(new MediaController(this));
video.bringToFront();
linear.addView(video);
}
}
public void setLogView(String date){
DataBaseMain dataBase = new DataBaseMain(this);
dataBase.open();
all = dataBase.dayLog(date);
dataBase.close();
if (all == null || all[0].length < 1 || all[3][0] == null || all[3][0].equals(""))
return;
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
for (int i = 0; i < all[0].length; i++){
String temporay = "";
for(int j = 0; j < all.length; j++)
{
temporay = temporay + " " + all[j][i];
}
Button mine = new Button(this);
mine.setText(temporay);
mine.setTextColor(getResources().getColor(R.color.black));
mine.setBackgroundColor(color.transparent);
mine.setLayoutParams(lp);
mine.setId(i);
mine.setOnClickListener(this);
linear.addView(mine);
//Toast.makeText(this, ""+i, Toast.LENGTH_SHORT).show();
}
}
It's probably because you have most of your LayoutParams' heights to LayoutParams.MATCH_PARENT. "MATCH_PARENT" means that you want the height of this element to be as big as the parent container. Not sure exactly what you're trying to accomplish layout wise, so I can't recommend a fix other than first trying to set the width to WRAP_CONTENT and taking it from there.