i mean editText created programmatically. I want to get the data inputted from those editText i created.
These are i've done so far.
VARIABLES
private GridLayout gridLayout;
//for tasks
int rowIndex = 2;
int colIndex = 1;
int rowIndex2 = 2;
int colIndex2 = 0;
int i=0;
int j=0;
//database variables
MyDBAdapter dbhandler;
To be able to create an editText in a gridlayout by a button click.
When "add new Task" button is clicked:
public void addTask(View view) {
i++;
Map<String, Integer> idsMap = new HashMap<String, Integer>();
String tname = "task" + Integer.toString(i);
EditText editText = new EditText(this);
GridLayout.LayoutParams param = new GridLayout.LayoutParams();
param.height = ViewGroup.LayoutParams.WRAP_CONTENT;
param.width = GridLayout.LayoutParams.MATCH_PARENT;
param.rowSpec = GridLayout.spec(rowIndex);
param.columnSpec = GridLayout.spec(colIndex);
editText.setTextColor(Color.BLACK);
editText.setBackgroundResource(android.R.drawable.edit_text);
editText.setText(tname);
editText.setLayoutParams(param);
TextView textView = new TextView(this);
GridLayout.LayoutParams param2 = new GridLayout.LayoutParams();
param2.rowSpec = GridLayout.spec(rowIndex2);
param2.columnSpec = GridLayout.spec(colIndex2);
textView.setPadding(30, 0, 0, 0);
textView.setTextColor(Color.BLACK);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setLayoutParams(param2);
if (rowIndex > 1) {
textView.setText("TASK "+Integer.toString(i)+": ");
editText.setId(i);
idsMap.put(tname, i);
}
gridLayout.addView(editText);
gridLayout.addView(textView);
rowIndex++;
rowIndex2++;
this.j = 0;
}
When "Add new Subtask" button is clicked:
public void addSubtask(View view) {
j++;
Map<String, Integer> idsMap = new HashMap<String, Integer>();
String taskno = "task" + Integer.toString(i) + "subtask" + Integer.toString(j);
EditText editText = new EditText(this);
GridLayout.LayoutParams param = new GridLayout.LayoutParams();
param.height = ViewGroup.LayoutParams.WRAP_CONTENT;
param.width = GridLayout.LayoutParams.MATCH_PARENT;
param.rowSpec = GridLayout.spec(rowIndex);
param.columnSpec = GridLayout.spec(colIndex);
editText.setTextColor(Color.BLACK);
editText.setBackgroundResource(android.R.drawable.edit_text);
editText.setText(taskno);
editText.setLayoutParams(param);
TextView textView = new TextView(this);
GridLayout.LayoutParams param2 = new GridLayout.LayoutParams();
param2.rowSpec = GridLayout.spec(rowIndex2);
param2.columnSpec = GridLayout.spec(colIndex2);
textView.setPadding(30,0,0,0);
textView.setTextColor(Color.BLACK);
textView.setLayoutParams(param2);
if (rowIndex > 1) {
textView.setText("Subtask "+Integer.toString(j)+": ");
editText.setId(j);
idsMap.put(taskno, j);
}
gridLayout.addView(editText);
gridLayout.addView(textView);
rowIndex++;
rowIndex2++;
}
IT WOULD LOOK LIKE THIS FOR EXAMPLE:
TASK 1: ___________
Subtask 1: ________
Subtask 2: ________
TASK 2: ___________
Subtask 1: ________
TASK 3: ___________
Assuming the user is done inputting the necessary info and clicks the submit button. THE PROBLEM COMES IN. I DONT KNOW HOW TO GET ALL THE VALUES BASED on the number of editText created by the user.
public void submit(){
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//implementation
String task1 = task1.getText().toString(); // It would only get task1
String subtask1 = task1subtask1.getText().toString(); // It would only get subtask1 of task 1
}
}
That kind of implementation is not usable since i dont know how many editTexts of tasks and subtasks that the user created. HELPPPP T___T
Every time you create an Edit Text use View.generateId() to generate an ID, store that ID in an HashMap or loop your container Views with getChildAt() and then, if its an EditText get its value.
Maybe you can set a custom tag for each edittext that you create.
You can determinate a specific generic tag for "Task" and an other for "Subtask" and after each creation, you set the tag to your edittext like that :
edittext.setTag(KEY, "task_X") where X is a incremental id.
After that, you can enumerate all children of your main container and check tags'children
List<EditText> allEdittext = new ArrayList<EditText>();
public void addSubtask(View view) {
j++;
Map<String, Integer> idsMap = new HashMap<String, Integer>();
String taskno = "task" + Integer.toString(i) + "subtask" + Integer.toString(j);
EditText editText = new EditText(this);
GridLayout.LayoutParams param = new GridLayout.LayoutParams();
param.height = ViewGroup.LayoutParams.WRAP_CONTENT;
param.width = GridLayout.LayoutParams.MATCH_PARENT;
param.rowSpec = GridLayout.spec(rowIndex);
param.columnSpec = GridLayout.spec(colIndex);
editText.setTextColor(Color.BLACK);
editText.setBackgroundResource(android.R.drawable.edit_text);
editText.setText(taskno);
editText.setLayoutParams(param);
TextView textView = new TextView(this);
GridLayout.LayoutParams param2 = new GridLayout.LayoutParams();
param2.rowSpec = GridLayout.spec(rowIndex2);
param2.columnSpec = GridLayout.spec(colIndex2);
textView.setPadding(30,0,0,0);
textView.setTextColor(Color.BLACK);
textView.setLayoutParams(param2);
if (rowIndex > 1) {
textView.setText("Subtask "+Integer.toString(j)+": ");
editText.setId(j);
idsMap.put(taskno, j);
}
allEdittext.add(editText);
gridLayout.addView(editText);
gridLayout.addView(textView);
rowIndex++;
rowIndex2++;
}
Then your get the values from the edit text
public void submit(){
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//implementation
String task1 = task1.getText().toString(); // It would only get task1
//i will be the position
String subtask1 = allEdittext.get(i).getText().toString();// It would only get subtask1 of task 1
}
}
Like this you can modify the code for addtask() function
Related
In this code i am able to create gridlayout. but the first item is in default view and the rest is like what i want. I try debug and I couldn't see what is wrong. Would you help me to solve this.
question="this is a sentence";
String sLetter;
String question = question.replace(" ", "");
//char[] charAr = question.toCharArray();
final ArrayList<String> letters = new ArrayList<>();
for (int k = 0; k < question.length(); k++) {
sLetter = Character.toString(question.charAt(k));
letters.add(sLetter);
}
Collections.sort(letters);
int i;
for (i = 0; i < letters.size();) {
int count = recursiveMethod(letters,i,1);
if (count>0) {
//region text add
View main_view = new View(context);
main_view.setLayoutParams(new LinearLayout.LayoutParams(100, ViewGroup.LayoutParams.WRAP_CONTENT));
gridLayout.setColumnCount(7);
if (question.length()<=7){
gridLayout.setRowCount(1);
}else if (question.length()<12){
gridLayout.setRowCount(2);
}else {
gridLayout.setRowCount(3);
}
GridLayout.Spec colSpan = GridLayout.spec(GridLayout.UNDEFINED,1);
GridLayout.Spec rowSpan = GridLayout.spec(GridLayout.UNDEFINED, 1);
GridLayout.LayoutParams gridParam = new GridLayout.LayoutParams(
rowSpan, colSpan);
gridParam.setGravity(Gravity.FILL_HORIZONTAL);
gridParam.setMargins(5, 10, 5, 10);
final TextView tv = new TextView(context);
tv.setText(letters.get(i).toUpperCase());
tv.setId(i);
tv.setPadding(15, 15, 15, 15);
tv.setTextColor(getResources().getColor(R.color.colorPrimaryLight));
RelativeLayout.LayoutParams relTv = new RelativeLayout.LayoutParams(80, ViewGroup.LayoutParams.WRAP_CONTENT);
relTv.addRule( RelativeLayout.CENTER_HORIZONTAL);
relTv.addRule( RelativeLayout.CENTER_VERTICAL);
tv.setLinksClickable(true);
tv.setTextSize(0, 60);
//tv.setLayoutParams(relTv);
CardView cardView = new CardView(context);
cardView.setCardBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
cardView.setRadius(10);
cardView.setCardElevation(5);
RelativeLayout relativeLayout = new RelativeLayout(context);
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
final TextView textCount = new TextView(context);
textCount.setText(Integer.toString(count));
RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
relParam.addRule(RelativeLayout.ALIGN_BOTTOM, i);
relParam.addRule(RelativeLayout.RIGHT_OF, i);
textCount.setTypeface(Typeface.DEFAULT_BOLD);
textCount.setTextColor(getResources().getColor(R.color.colorPrimaryLight));
textCount.setTextSize(0, 30);
textCount.setPadding(0,5,5,0);
//textCount.setLayoutParams(relParam);
relativeLayout.addView(tv,relTv);
relativeLayout.addView(textCount,relParam);
cardView.addView(relativeLayout);
//llLetters.addView(tv, lp);
gridLayout.addView(cardView,gridParam);
cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(context, tv.getText()+ "" + textCount.getText(), Toast.LENGTH_SHORT).show();
}
});
//llLetters.addView(gridLayout);
//endregion
i = i + count;
}
else {
i++;
}
}
The first letter of image is at the top left. I want to show that at the bottom right side of the letter. Would you help me to solve problem? Thanks =)
The problem lies here:
relParam.addRule(RelativeLayout.ALIGN_BOTTOM, i);
relParam.addRule(RelativeLayout.RIGHT_OF, i);
If you pass a zero to addRule, it is interpreted as false. Therefore you say, that ALIGN_BOTTOM should be false in your first letter, when i is zero.
See the documentation:
parameter: subject, int: the ID of another view to use as an anchor, or a boolean value (represented as RelativeLayout.TRUE for true or 0 for false).
I have a RelativeLayout that allows players of a game to input personal details such as name and define their role. The Layouts are created dynamically depending on how many players there are (This is defined earlier in the activity).
This is all contained in a for loop to generate each layout.
I am trying to add an onclicklistener so that as each player enters their details their individual data will be stored.
The code I have used so far produces an ArrayIndexOutOfBoundsException.
Could you please explain how I should correct this code, thanks.
public void buildDynamicViews(Integer input1) {
int textId = 10;
//Arrays
groupDetailsList = (RelativeLayout)findViewById(R.id.playersNameLayout);
row_Number = new TextView[input1];
spinnerArray = new Spinner[input1];
groupDetailsContainer = new RelativeLayout[input1];
firstNameText = new TextView[input1];
lastNameText = new TextView[input1];
fNameInput = new EditText[input1];
lNameInput = new EditText[input1];
playerDetailsButton = new Button[input1];
//displays lines of text with instructions
text = (TextView)findViewById(R.id.displayMessage);
ViewGroup.LayoutParams params = text.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
text.setId(textId);
((MarginLayoutParams) params).setMargins(0,0,0,20);
text.setLayoutParams(params);
String txt1 = getResources().getString(R.string.player_details_Title);
String txt2 = getResources().getString(R.string.players_details_message);
String txt = txt1+"\n"+txt2;
text.setText(txt);
//Scrollview to contain relativeLayouts created in for loop
ScrollView scroll = (ScrollView)findViewById(R.id.playerNameScroller);
RelativeLayout.LayoutParams scrollerLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
scrollerLayoutParams.addRule(RelativeLayout.BELOW, text.getId());
scroll.setLayoutParams(scrollerLayoutParams);
//Loop
for ( i = 0; i < input1; i++) {
//generate relativelayout to house each individual players data input section
groupDetailsContainer[i] = new RelativeLayout(this);
groupDetailsContainer[i].setId(20+i);
RelativeLayout.LayoutParams containerParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
if(i==0){
containerParams.addRule(RelativeLayout.BELOW ,text.getId());
}
else
{
containerParams.addRule(RelativeLayout.BELOW, (i+19));
}
containerParams.setMargins(0,0,0,20);
groupDetailsContainer[i].setLayoutParams(containerParams);
//generate left hand box for player number
row_Number[i]= new TextView(this);
LayoutParams rowNumParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rowNumParams.addRule(RelativeLayout.ALIGN_LEFT);
if(i ==0)
rowNumParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
else
{
rowNumParams.addRule(RelativeLayout.BELOW, (i-1));
}
row_Number[i].setLayoutParams(rowNumParams);
row_Number[i].setText("Details for Player Number:" + (i+1));
row_Number[i].setHeight(80);
row_Number[i].setTextSize(20);
row_Number[i].setWidth(125);
row_Number[i].setId((i+1));
//generate box for text first name
RelativeLayout.LayoutParams fNameParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
fNameParams.addRule(RelativeLayout.RIGHT_OF, row_Number[i].getId() );
firstNameText[i] = new TextView(this);
firstNameText[i].setTextSize(20);
firstNameText[i].setHeight(40);
firstNameText[i].setText("Enter First Name:");
firstNameText[i].setId(31*(i+1));
firstNameText[i].setLayoutParams(fNameParams);
//generate EditTextbox for first name input
RelativeLayout.LayoutParams fNameinputParams = new LayoutParams(200, 25);
fNameinputParams.addRule(RelativeLayout.RIGHT_OF, firstNameText[i].getId());
fNameinputParams.addRule(RelativeLayout.ALIGN_BASELINE, firstNameText[i].getId());
fNameinputParams.setMargins(10, 0, 10, 0);
fNameInput[i] = new EditText(this);
fNameInput[i].setLayoutParams(fNameinputParams);
fNameInput[i].setId(32*(i+1));
fNameInput[i].setTextSize(20);
//generate button
RelativeLayout.LayoutParams detailsButtonParams = new LayoutParams (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
playerDetailsButton[i] = new Button(this);
detailsButtonParams.addRule(RelativeLayout.RIGHT_OF, spinnerArray[i].getId());
detailsButtonParams.addRule(RelativeLayout.ALIGN_BOTTOM, spinnerArray[i].getId());
detailsButtonParams.setMargins(20, 0, 20, 0);
playerDetailsButton[i].setLayoutParams(detailsButtonParams);
playerDetailsButton[i].setWidth(250);
playerDetailsButton[i].setHeight(20);
playerDetailsButton[i].setText("Press to save details");
//generate OnClick Listener for button
PlayerDetailsButtonOnClick = new View.OnClickListener() {
#Override
public void onClick(View v) {
String FName = firstNameText[i].toString();
String LName = lastNameText[i].toString();
String fullName = FName+" "+LName;
toast(fullName);
}
};
playerDetailsButton[i].setOnClickListener(PlayerDetailsButtonOnClick);
//wrap each view to the layout
groupDetailsContainer[i].addView(row_Number[i]);
groupDetailsContainer[i].addView(fNameInput[i]);
groupDetailsContainer[i].addView(lNameInput[i]);
groupDetailsContainer[i].addView(firstNameText[i]);
groupDetailsContainer[i].addView(lastNameText[i]);
groupDetailsContainer[i].addView(spinnerArray[i]);
groupDetailsContainer[i].addView(playerDetailsButton[i]);
groupDetailsList.addView(groupDetailsContainer[i]); }
One issue may also be how to pass the string values from the loop into the onClick() function. Thanks
The pojo class is a simple class (you can add the data trough the setters or make a simple constructor):
private class POJOName {
String firstName;
String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
this class can be used to store the first name and also the last name and then you use playerDetailsButton[i].setTag( here you put the pojo object ); and then
//generate OnClick Listener for button
PlayerDetailsButtonOnClick = new View.OnClickListener() {
#Override
public void onClick(View v) {
POJOName pojo = (POJOName)v.getTag();
String fullName = pojo.getFirstName()+" "+pojo.getLastName();
toast(fullName);
}
};
I also managed to solve this a second way as well.
I assigned a final int j variable to the int i value within the for loop.
Then in the OnClick() I referenced the relevant editview like this [class].this.[viewname][j].gettext().toString();
So my code looks like this:
final int j = i;
playerDetailsButton[i].setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.d("detailsOnClick", "Button Pressed");
inputFName = GroupDetails1.this.fNameInput[j].getText().toString();
Log.d("inputFNameOnClick", inputFName);
inputLName = (GroupDetails1.this.lNameInput[j].getText()).toString();
toast(inputFName);
toast(inputLName);
}
Thanks for all your help and input
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.
Hi guy's i have a problem with Android...
This is a part of my code:
setContentView(R.layout.activity_main);
TableLayout MainTable = (TableLayout) findViewById(R.id.main_table);
JSONArray Jobj = new JSONArray(result_set);
String url_img = null;
String url_video = null; //MUST CONTAINS THE URL OF MY VIDEO
for (int i = 0; i < Jobj.length(); i++) {
TableRow row = new TableRow(getApplicationContext());
row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
row.setPadding(0, 14, 2, 14);
JSONObject titoli = Jobj.getJSONObject(i);
Integer id = titoli.getInt("id_video");
String titolo = titoli.getString("nome_video");
String immagini = titoli.getString("video_img");
String video_url = titoli.getString("url_video");
/* video_url : this is the variable that i change (and contains the relative path that i obtains parsing json array) */
Pattern p = Pattern.compile("^(https?|ftp|file)://[-a-zA-Z0-9+&##/%?=~_|!:,.;]*[-a-zA-Z0-9+&##/%=~_|]");
Matcher m = p.matcher(immagini);
Pattern v = Pattern.compile("^/video/[-a-zA-Z0-9+&##/%?=~_|!:,.;]*[-a-zA-Z0-9+&##/%=~_|]");
Matcher vm = v.matcher(video_url);
// Path video
if (vm.matches() == false) {
url_video = path_youtube + video_url; // SECOND ERROR HERE
} else if (vm.matches() == true) {
url_video = path_an_tv + video_url; // SECOND ERROR HERE
}
// Path image
if (m.matches() == false) {
url_img = path + immagini;
} else if (m.matches() == true) {
url_img = immagini;
}
ImageView img = new ImageView(getApplicationContext());
img.setAdjustViewBounds(true);
img.setMaxHeight(140);
img.setMaxWidth(140);
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url_img).getContent());
img.setImageBitmap(bitmap);
LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
final TextView txt = new TextView(getApplicationContext());
txt.setGravity(Gravity.LEFT | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
txt.setLayoutParams(params);
txt.setTextSize(18);
txt.setBackgroundColor(Color.WHITE);
txt.setTypeface(null, Typeface.BOLD);
txt.setTextColor(Color.BLACK);
txt.setId(id);
txt.setText(titolo);
txt.setClickable(true);
row.addView(img);
row.addView(txt);
MainTable.addView(row);
txt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url_video)));
/* FIRST ERROR HERE, url_video contains the absolute url of my video*/
}
});
}
When i try compile my project an error occours:
*Cannot refer to a non final variable url_video inside a innner class defined in a different method...*
If I change url video into final another error occours:
The final local variable cannot be assigned. it must be blank and not using a compound assignment
How I can fix it ?
UPDATE I FIX IT REPLACING WITH THIS:
final TextView txt = new TextView(getApplicationContext());
txt.setGravity(Gravity.LEFT | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL );
txt.setLayoutParams(params); txt.setTextSize(18); txt.setBackgroundColor(Color.WHITE);
txt.setTypeface(null, Typeface.BOLD); txt.setTextColor(Color.BLACK);
txt.setId(id); txt.setTag(url_video); txt.setText(titolo); txt.setClickable(true);
row.addView(img);
row.addView(txt);
MainTable.addView(row);
txt.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse((String) txt.getTag())));
}
});
}
Define it in class level private String video_url;
You can't access a variable defined within onCreate() within OnClick() Because the scope of oncreate is over when you get a click. So you must keep the variable scope alive.
UPDATE
Yeah, Its simple,
public class YourClass {
private String video_url;
public void OnCreate()
{
}
}
Just make this an instance variable
String url_video = null;
That is define this inactivity.
I have developed a form in dynamically using some edit text,check boxes,radio buttons and buttons.I have created form successfully ,but how i can get the values from that and stored in database.Please can any one help me.
Thanking in Advance.
public void textView() {
idText++;
i++;
LinearLayout linearLayoutHorizantal1 = new LinearLayout(
getApplicationContext());
linearLayoutHorizantal1.setOrientation(LinearLayout.HORIZONTAL);
/*
* LinearLayout.LayoutParams params = new
* LinearLayout.LayoutParams(LayoutParams
* .WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
* linearLayoutHorizantal1.setGravity(Gravity.RIGHT);
*/
txtQuetion = new TextView(getApplicationContext());
txtQuetion.setText(i + ". " + strQuestionText);
txtQuetion.setTextColor(Color.BLACK);
txtQuetion.setTextSize(20);
txtQuetion.setId(idText);
linearLayoutHorizantal1.addView(txtQuetion);
linearLayoutDynamicAdd.addView(linearLayoutHorizantal1);
}
public void RadioButtons() {
radiogroup = new RadioGroup(getApplicationContext());
radiogroup.setOrientation(RadioGroup.HORIZONTAL);
RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(
SurveyFillActivity.this, null);
params.setMargins(10, 10, 10, 0);
linearLayoutDynamicAdd.addView(radiogroup);
for (int j = 0; j < answersList.length; j++) {
if (answersList[j] != null) {
idRadio++;
rb = new RadioButton(getApplicationContext());
rb.setId(idRadio);
rb.setText(answersList[j]);
rb.setTextColor(Color.BLACK);
rb.setButtonDrawable(R.drawable.radio_custom);
// rb.setChecked(true);
rb.setLayoutParams(params);
radiogroup.addView(rb);
}
}
}
private EditText editText(int _intID) {
idEditBox++;
final LayoutParams lparams = new LayoutParams(350, 50);
final EditText et = new EditText(this);
lparams.leftMargin = 20;
lparams.topMargin = 10;
et.setLayoutParams(lparams);
et.setWidth(32);
et.setEms(50);
et.setBackgroundResource(R.drawable.customborder_backbutton);
/*
* EditText et = new EditText(getApplicationContext());
* et.setId(idEditBox); et.setHeight(60); et.setWidth(50);
*/
//et.setBackgroundColor(Color.WHITE);
String s1 = et.getText().toString();
linearLayoutDynamicAdd.addView(et, lparams);
return et;
}
The above code for creating forms and i need to get the values form it and store in Database.
Create the arrays for texviews and radiobuttons ...what ever you need in your form.
take this as reference
TextView tv[] = new TextView[HowManyYouNeed];
TextView tvsa = new TextView(YourContax);
tv[position]=tvsa;//position like o ..1..2
tv[0].getText();
May be help full..