Git CheatSheet

A little compilation of the git command sequences i use most, to avoid forgetting’em:

Commit / Push to repo:

cd /c/projects/ProjectName
git status – Have a look at the files that have been modified, included, or deleted after the last commit
git add . – If i consider that all files should be included (this is the most usual case for me)
git commit -am “refs #tasknumber description of the implemented features” – commit changes
git push origin mybranchname – push commited changes to remote repository

Getting another developer’s branch (lets call him X):

git checkout devX
git pull origin devX

Merging my branch with another developer’s branch (again, X’s branch)

git checkout devX
git pull origin devX
git checkout mybranch
git merge devX

Directly pulling someone else’s brach to mine.

git checkout devX
git pull origin devX
git checkout mybranch
git pull origin devX

Getting the repo

cd /c/projects/Android/
git clone https://github.com/voghDev/android-examples.git
cd /c/projects/Android/android-examples
cat “This is a test” > README.md
git commit -am “Updated readme file”
git push

[Android] MultiChoiceListener functionality in your ListViews, in 6 easy steps (Advanced)

This tutorial assumes that you know how to handle ListViews, ListAdapters, and Fragments. If someone needs deeper explaination, ask it on a comment.

Step 1.- MyFragment.java

public class MyFragment extends Fragment implements MultiChoiceModeListener
{
...

Step 2.- my_fragment.xml

<ListView 
 android:id="@+id/my_list"
 android:layout_height="match_parent"
 android:layout_width="wrap_content"
 android:choiceMode="multipleChoiceModal"
 android:entries="@array/values"
 />

Step 3.- MyFragment.java – onViewCreated()

mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View arg1, int position,
long arg3) {
mListView.setItemChecked(position, !mListView.isItemChecked(position));
}
});
mListView.setMultiChoiceModeListener(this);

Step 4.- MyFragment.java

@Override
 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
 return false;
 }
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,long id, boolean checked) {
}

Step 5.- my_fragment_row.xml

<com.company.myapp.view.CheckableRelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 > 

Step 6.- CheckableRelativeLayout.java

public class CheckableRelativeLayout extends RelativeLayout implements Checkable {
 private boolean mChecked;

 public CheckableRelativeLayout(Context context) {
 super(context);
 }
 
 public CheckableRelativeLayout(Context context, AttributeSet attrs) {
 super(context, attrs);
 }

 public CheckableRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
 super(context, attrs, defStyle);
 }
  
 public void setChecked(boolean checked) {
 mChecked = checked;
 refreshDrawableState();
 
 int bgResource = checked ? R.drawable.selection_mask_blue : android.R.color.transparent;
 setBackgroundResource(bgResource);
 }

 public boolean isChecked() {
 return mChecked;
 }

 public void toggle() {
 setChecked(!mChecked);
 }
}