Add and Remove view dynamically keep track of child views

I have a old example of "Add and Remove view dynamically". Somebody ask how the Remove button keep track of the views. So I modify the example to explain in more details.


In this example, when user click on the Add button, it will create a child View, addView. The addView have a Button, buttonRemove. The buttonRemove have its own OnClickListener object. The OnClickListener object refer to the specified addView when it is created.

That means the OnClickListener object of the buttonRemove in the first child view("abc") not the same object in the second child view("abcdef"), not the same object in the third child view("abcdefghi")...All have its own individual OnClickListener object. And each OnClickListener object refer to a specified addView object. Such that it can keep track of the child Views, addView.


MainActivity.java
package com.blogspot.android_er.androiddynamicview;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText textIn;
Button buttonAdd;
LinearLayout container;
TextView reList, info;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textIn = (EditText)findViewById(R.id.textin);
buttonAdd = (Button)findViewById(R.id.add);
container = (LinearLayout)findViewById(R.id.container);
reList = (TextView)findViewById(R.id.relist);
info = (TextView)findViewById(R.id.info);
info.setMovementMethod(new ScrollingMovementMethod());

buttonAdd.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
textOut.setText(textIn.getText().toString());
Button buttonRemove = (Button)addView.findViewById(R.id.remove);

final View.OnClickListener thisListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
info.append("thisListener called: " + this + " ");
info.append("Remove addView: " + addView + " ");
((LinearLayout)addView.getParent()).removeView(addView);

listAllAddView();
}
};

buttonRemove.setOnClickListener(thisListener);
container.addView(addView);

info.append(
"thisListener: " + thisListener + " "
+ "addView: " + addView + " "
);

listAllAddView();
}
});
}

private void listAllAddView(){
reList.setText("");

int childCount = container.getChildCount();
for(int i=0; i<childCount; i++){
View thisChild = container.getChildAt(i);
reList.append(thisChild + " ");
}
}
}


layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

android_layout_width="match_parent"
android_layout_height="match_parent"
android_orientation="horizontal"
android_padding="16dp"
tools_context="com.blogspot.android_er.androiddynamicview.MainActivity">


<LinearLayout
android_layout_width="0dp"
android_layout_height="match_parent"
android_layout_weight="1"
android_orientation="vertical">

<RelativeLayout
android_layout_width="match_parent"
android_layout_height="wrap_content">

<Button
android_id="@+id/add"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_alignParentRight="true"
android_text="Add" />

<EditText
android_id="@+id/textin"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_layout_alignParentLeft="true"
android_layout_toLeftOf="@id/add" />
</RelativeLayout>

<LinearLayout
android_id="@+id/container"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_orientation="vertical"></LinearLayout>

</LinearLayout>

<LinearLayout
android_layout_width="0dp"
android_layout_height="match_parent"
android_layout_weight="1"
android_orientation="vertical">

<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="center_horizontal"
android_autoLink="web"
android_text="http://android-er.blogspot.com/"
android_textStyle="bold" />

<TextView
android_id="@+id/relist"
android_layout_width="match_parent"
android_layout_height="0dp"
android_layout_weight="1"
android_textStyle="bold"
android_background="#E0E0E0"/>
<TextView
android_id="@+id/info"
android_layout_width="match_parent"
android_layout_height="0dp"
android_layout_weight="1"
android_textStyle="italic"
android_background="#D0D0D0"
android_gravity="bottom"/>

</LinearLayout>
</LinearLayout>


layout/row.xml, the layout of the child views.
<RelativeLayout 

android_layout_width="match_parent"
android_layout_height="wrap_content">
<Button
android_id="@+id/remove"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_alignParentRight="true"
android_text="Remove"/>
<TextView
android_id="@+id/textout"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_layout_alignParentLeft="true"
android_layout_toLeftOf="@id/remove"/>
</RelativeLayout>


download filesDownload the files (Android Studio Format) .

Its another approach to share a common OnClickListener between all buttonRemove.

more:
- Add and Remove view dynamically, with EditText/AutoCompleteTextView inside

Read More..

California schools inspire students and teachers to keep their “heads in the cloud”




Editors note: California schools are seeing great success with Google for Education. We talked to educators and administrators to reflect on how technology has changed what it means to teach and learn in California. From encouraging strategic thinking to improving writing skills, technology has enhanced the learning experience for students across the state.


For California students, backpacks are getting lighter as schools turn to Chromebooks, Google Apps for Education and cloud-based education apps in place of textbooks, pencils and paper. This new approach to learning is helping students improve their writing and critical thinking skills, while helping teachers and staff increase productivity. Inspired by how schools are innovating with cloud technology across the region, we’re highlighting a few of the successes in California schools:

1. Using the cloud to improve writing quality and creativity 


While writing is predominantly a solitary activity, timely feedback is crucial for helping students to improve their skills. Between 2010 and 2014, the administration at Del Mar Union School District in San Diego introduced Chromebooks and Google Apps for Education to all third through sixth grade classes at all eight schools throughout the district. With these new tools, Del Mar’s staff has seen students’ writing quality dramatically improve. With access to the cloud, students can easily share their assignments with other students and teachers to receive feedback immediately. By storing documents in Google Drive, students can also rest assured that their most recent work is saved and secure.

This new model of classroom collaboration inspires students to experiment and take more risks, knowing that they’ll receive feedback from teachers before getting a final grade.

“Students’ vocabulary has increased. Now they’re using ‘million dollar words’ instead of ‘five dollar words’,” says fourth-grade teacher Stephanie Sullins. “They’re not afraid of making a mistake.”

Chromebooks and Google Apps have also been vital in meeting rigorous Common Core State Standards for writing. “The number of students reaching the top score on the state writing tests dramatically increased after the introduction of Chromebooks,” Sullins says.

2. Using the cloud to create an interactive educational environment


Los Angeles’ KIPP Academy of Opportunity and KIPP LA Prep discovered that the ability to work together, aided by cloud-based tools, pushes students to think more critically. As part of Google’s pilot program that began in spring 2011, the school district introduced 400 Chromebooks — a number that has now grown to 5,000 Chromebooks with hundreds more added each year. KIPP LA decreased their costs by deploying Chromebooks because they no longer needed to purchase expensive software licenses, servers, security solutions, and maintenance plans for each device.

The educational impact for students has been notable. There has been a big shift from direct instruction and memorization of notes to an interactive classroom. Now, students work with one another on projects and share information through Google Hangouts and Google Drive.

“Students create and collaborate, rather than memorize and regurgitate,” said James Sanders, a former social science teacher at KIPP LA Schools. “It’s a better, more authentic model for learning.” As one of Sander’s students explains: “We walk into a social studies class, grab a computer, and check out Mr. Sanders’s blog, then we follow the tasks he sets.”

3. Using the cloud to inspire teachers and students to think outside the box 


The Dublin Unified School District’s teachers and staff needed a better solution for communication and for helping students stay organized. They piloted Google Apps for Education and Google Classroom, and received rave reviews from parents, teachers and students. Now, teachers, students and staff enjoy having one unified platform for email, calendar and document sharing — accessible anytime, from any device.

Technology has become deeply entrenched in Dublin schools. Dublin High School includes among its student body, Hania Guiagoussou, the youngest recipient to-date of Oracle’s Duke’s Choice Award for java programming. At Dublin High School, Guiagoussou was one of the many students who participated in the school’s computer programming class. Now, her first project, WaterSaver, is an award-winning, Java-based system that intelligently controls water sources. Guiagoussou’s story is one of many where technology has inspired a student to reach farther than she ever expected.

Collaboration and sharing in the cloud has made it infinitely easier for schools to exchange information. Using Google Classroom, a student can share writing assignments with a teacher and receive instant feedback. With a few taps, a teacher can share lesson plans or curriculum ideas with her colleague using the Drive mobile app. Administrators know who’s attending the next staff meeting by glancing at a Calendar invite. California schools are doing incredible things by taking a leap toward the cloud.

Check out more inspirational stories from schools.

We’ve heard great stories from many of you about how you’re using technology to do amazing things in your schools, so were going across the U.S. to see for ourselves! Check out the map below to see where we’ve been. We’d love to hear what’s happening in your state, so please share your story on Twitter or Google+ and tag us (@GoogleForEdu) or include the #GoogleEdu hashtag.


Read More..

Keep BACKUPS!!!!

I was just uploading the images from a nice walk at the marina and breakwater at Dick Bell Park today and thought it would be a good idea to back up my files. I thought there might be almost a thousand new files since the last back up and that would be heart-breaking to lose.

It’s running right now, and I was shocked to see how many images I have shot or processed in the last 3 or 4 weeks. OMG!

image

So remember to back up your images more regularly. You will regret it if you have a sudden crash and no second copy.


What I do for backups:

I have a 1TB Seagate Free Agent drive on a USB 2 port for backing up my email and all my files. I have everything I have ever written or received (that mattered) going back more than 14 years.

I have a 2TB Lacie Porsche drive on a USB 3 port for image backup. It took a while to get the drivers right on my USB 3 ports, but that’s working now and it was well worth it. Especially for image copy with my new USB reader.

I run a utility called “AllWay Sync” which is very inexpensive for the Pro version. It performs incremental backups and the jobs can be set up with any type of synchronization you desire. I use a one way copy with deletion propagation for images. I am very careful when I delete though, so if you are rather cavalier, I would suggest that you do not propagate deletions.

It is really that simple. I do  not have AllWay Sync running all the time, as it eats a lot of memory. But I could afford it now, so I might let it watch t6he file system and propagate in real time. That way I am protected within a 30 second window.

Read More..

Blog Archive

Powered by Blogger.